Zuul 转发错误 - 尝试连接到其他(未知)IP



我已经为我的 Spring 启动应用程序配置了 zuul 代理和 eureka 命名服务器。Zuul 代理在端口8765上运行,尤里卡在端口8761上运行。 另外两个微服务,用户服务和消息服务在端口80818082上运行。

此外,我还为 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;
}
}

应用程序.yml 的 Zuul 代理

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消息服务的 IP 地址是 169.254.3.10

这是问题所在

当我通过 zuul 代理 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 代理容器 ip169.254.3.10

当我使用相同的 Zuulserver 在本地主机和 DEV 环境中开发微服务时,我的项目上出现了这个问题(当我在本地主机上启动微servis 时,它连接到 DEV env 上的 zullserver(。然后,当我尝试通过 zuulserver 调用某些操作时,它试图连接到不在 DEV env 上的微服务。但在我的机器上。

我怀疑您这边的相同问题和您正在开发应用程序的 IP 是 172.22.97.14:8081。

最新更新