记录一次zuul排错

某个突然出现的Bug

在做微服务的时候,后端启动了几个端口,之前还想着在前端配置不同的端口方便测试,其实是可以在Zuul中设置一个共同的入口的。Zuul的配置如下(暂且不做拦截)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
server:
port: 8081
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: interest-zuul
zuul:
host:
connect-timeout-millis: 10000
socket-timeout-millis: 10000
add-proxy-headers: true
sensitive-headers:
routes:
interest-user:
path: /interest/user/**
serviceId: interest-user
stripPrefix: false
interest-approval:
path: /interest/approval/**
serviceId: interest-approval
stripPrefix: false
interest-Meeting:
path: /interest/Meeting/**
serviceId: interest-Meeting
stripPrefix: false
interest-file:
path: /interest/file/**
serviceId: interest-file
stripPrefix: false
interest-risk:
path: /interest/risk/**
serviceId: interest-risk
stripPrefix: false
interest-template:
path: /interest/template/**
serviceId: interest-template
stripPrefix: false

ribbon:
ReadTimeout: 10000
ConnectTimeout: 10000
logging:
# 你需要存储日志的目录
file: D:/interest/file/log/interest.log
#测试环境
#file: /www/wwwroot/hhzhutest.com/log/interest.log
level:
org.springframework.cloud: DEBUG
com.interest.zuul: DEBUG

这样就可以通过8081端口访问其他服务。后台启动eureka(8761),zuul(8081),user(8099)。访问user模块的接口,首先通过8099访问user模块的swagger测试:

image-20200330011233220

ok,没问题。现在通过zuul的8081端口访问swagger,不行,后台报错如下:

image-20200330011530071

超时了?(对,没错,就是超时了)。

打开eureka查看没错是注册过来了啊

image-20200330025332776

然后打开前端,通过8081端口访问user,woc,虽然报红,但是验证码是发过来了,后台的user模块也是在打印日志,明显是已经通过zuul的端口访问到user来了。这就很奇怪了,网上搜了一天,没有一个靠谱的答案。百思不得其解,既然接口已经访问到了,说明这个zuul的配置也咩问题啊,难道,是swagger的配置出了问题??打开swagger配置,没发现什么幺蛾子。陷入了深思。。。。。。

这时候坚定一定是zuul的配置出问题了,打开zull的配置和git上的记录对比,没发现变动。去github上拉取框架源码,完全相同。到这事情似乎已经没办法进展了。然后去谷歌zuul的常规配置。和自己的配置对比:

1
2
3
4
5
6
7
8
9
routes:
interest-user:
path: /interest/user/**
serviceId: interest-user
stripPrefix: false
interest-approval:
path: /interest/approval/**
serviceId: interest-approval
stripPrefix: false

不对劲啊,既然zull是把别的端口映射过来,现在加入后台微服务开50个,routes的配置虽然写了路径,但是具体去找哪个端口??难道是一个一个找?这样看来确实需要很长时间。OK,我再给你点时间,原来是10000现在给你50000够了吧??

1
2
3
ribbon:
ReadTimeout: 50000
ConnectTimeout: 50000

重启之后,通过8081访问user,一直在转圈圈,转了一会发现真的访问到了,woc??是看到了swagger,但是我的目的不是要看swagger啊,我的目的是要接口,这么长个时间,那还开发个毛线,这肯定无法睡服自己啊,这时候想,spring这么优秀的东西,不至于让 zuul自己去找映射的,肯定是可以配置的,打开百度搜索了一下,发现果然可以,加上后:

1
2
3
4
5
6
7
8
9
10
11
routes:
interest-user:
path: /interest/user/**
url: 127.0.0.1:9088
serviceId: interest-user
stripPrefix: false
interest-approval:
path: /interest/approval/**
url: 127.0.0.1:8099
serviceId: interest-approval
stripPrefix: false

这次重启后端通过8081访问user的swagger,如丝般顺滑。原框架作者留下的坑加上自己菜。。。。

为此

重装了三次IDEA

熬了两个这么晚

他妈的晚安QAQ

等等等等,还发现一个好用的IDEA插件—-RestfulToolKit,

image-20200330024103040

这这这??这还要什么postman和swagger啊。

晚安。。。。。

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

请我喝杯咖啡吧~

支付宝
微信