【发布时间】:2019-12-27 12:02:23
【问题描述】:
我已经为我的 Spring Boot 应用程序配置了 zuul 代理和 eureka 命名服务器。 Zuul 代理在端口8765 上运行,eureka 在端口8761 上运行。
还有另外两个微服务,user-service 和 message-service 在端口 8081 和 8082 上运行。
我还为 zuul 代理服务使用了 swagger,我可以在一个地方找到所有微服务 api。
Zuul 代理服务中的 Swagger 配置
@Component
@Primary
@EnableAutoConfiguration
public class Controller implements SwaggerResourcesProvider{
@Override
public List<SwaggerResource> get() {
List<SwaggerResource> resources= new ArrayList<>();
SwaggerResource user = new SwaggerResource();
user.setName("USER-SERVICE");
user.setLocation("/api/user/v2/api-docs");
user.setSwaggerVersion("2.0");
resources.add(user);
SwaggerResource message = new SwaggerResource();
message.setName("MESSAGE-SERVICE");
message.setLocation("/api/message/v2/api-docs");
message.setSwaggerVersion("2.0");
resources.add(message);
return resources;
}
}
Zuul 代理的application.yml
server:
port: 8765
eureka:
client:
serviceUrl:
defaultZone: http://eureka-naming-server:8761/eureka/
instance:
prefer-ip-address: true
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
zuul:
prefix: /api
sensitive-headers: Cookie,Set-Cookie
routes:
user-service:
path: /user/**
service-id: USER-SERVICE
message-service:
path: /message/**
service-id: MESSAGE-SERVICE
我还使用docker-compose 文件以默认子网 (169.254.3.0/24) 启动 docker 微服务。
用户服务的ip地址是169.254.3.6 message-service的ip地址是169.254.3.10
问题来了
当我通过 zuul proxy swgger ui 调用这些服务时,我经常收到 500 错误。这是我第一次点击特定的网址,它会引发 500 错误。 但经过几次尝试后,我得到了回应。
指示问题的 Zuul 日志
com.netflix.zuul.exception.ZuulException: Forwarding error
...
Caused by: com.netflix.client.ClientException: null
...
Caused by: java.lang.RuntimeException: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to 172.22.97.14:8081 [/172.22.97.14] failed: connect timed out
...
Caused by: java.net.SocketTimeoutException: connect timed out
我不知道 172.22.97.14:8081,为什么不尝试连接 172.22.97.14:8081 而不是连接到 169.254.3.6: 8081
有人可以帮我了解这里发生了什么..
任何帮助将不胜感激!
[编辑]
zuul代理容器ip为169.254.3.10
【问题讨论】:
-
我认为
169.254.3.6在你的情况下是不可路由的。你能连接到那个地址吗? -
@LinPy 我可以从服务器连接到 169.254.3.6。
telnet 169.254.3.6 8081工作正常。 -
我的意思是远程不是来自本地 IP 的位置
-
配置中定义的端口
8081在哪里,我看到服务器尝试连接到端口8084 -
@LinPy 对不起。我放错了日志。无论如何,在端口
8084中,我也在为此运行我的管理服务相同的问题。我已经编辑了帖子。
标签: spring-boot docker routes netflix-eureka netflix-zuul