我在Heroku上有几个微服务 - eureka-server,Zuul服务器和一些应用程序服务。
当我尝试通过 Zuul 网关访问我的任何服务(例如"service1"(时,Zuul 无法将请求转发到相应的服务(当我尝试在本地运行它们时,一切正常(。我在 Zuul 日志中发现了以下错误:
com.netflix.zuul.exception.ZuulException: Forwarding error
Caused by: com.netflix.client.ClientException: Load balancer does not have the available server for the client: service1
以下是我的服务的配置:
1( "zuul server" application.yml
server:
port: ${PORT:8000}
zuul:
prefix: /api
ignoredServices: '*'
routes:
service1:
path: /path_for_service1/**
serviceId: service1
strip-prefix: false
...
management:
endpoints:
web:
exposure:
include: "*"
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_URL:http://localhost:5000}/eureka/
2("尤里卡服务器">应用程序.yml
server:
port: ${PORT:5000}
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
3.1( "服务1">应用程序.yml
server.port=${PORT:8081}
eureka.client.service-url.defaultZone=${EUREKA_URL:http://localhost:5000}/eureka/
3.2( "service1" bootstrap.yml
spring:
application:
name: service1
所有微服务都在尤里卡仪表板中可见。
如果我将 zuul 路由更改为硬编码的 url,它运行良好,但这不是我想要的。
zuul:
prefix: /api
ignoredServices: '*'
routes:
service1:
path: /path_for_service1/**
url: http://url_of_service_1
strip-prefix: false
你能帮我解决这个问题吗?
最后,我找到了根本原因:)默认情况下,所有服务都使用 heroku 主机名在 eureka 中注册(如"085930c7-b893-4b34-88a7-6e37fbe7fa0f"(,这在外面无法访问。但是服务可以通过域名访问。所以我只是将域名设置添加到每个服务的属性 (https://blog.heroku.com/managing_your_microservices_on_heroku_with_netflix_s_eureka(
eureka:
instance:
non-secure-port: 80
hostname: ${DOMAIN_NAME}
现在它起作用了。