首页 > 解决方案 > Zuul 无法使用动态端口微服务进行路由

问题描述

我有一个带有动态端口的微服务,即server.port=0. 微服务在 eureka 上得到了很好的注册,它已经启动并运行了。

但是,当我尝试通过 Zuul 网关访问它时,它无法处理我的 zuul 网关中的以下日志。

c.netflix.loadbalancer.BaseLoadBalancer  : Client: book instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=book,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
c.netflix.config.ChainedDynamicProperty  : Flipping property: book.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client book initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=book,current list of Servers=[192.168.60.1:0],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;  Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:192.168.60.1:0;    Zone:defaultZone;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 05:30:00 IST 1970;  First connection made: Thu Jan 01 05:30:00 IST 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@4dbc2e52

但是,当我将微服务 ( book) 的端口更改为非动态端口时server.port = 8081,一切都运行良好,并且每次我也必须重新启动 zuul 应用程序。我猜当其中一个微服务更改端口时,它并不顺利。

让我分享application.yml两个文件的内容。

微服务(书),application.yml

spring:
  application:
    name: book

server:
  port: 0 # I change it between 0 and 8081 (8081 works like a charm)

eureka:
  client:
    service-url:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
  instance:
    prefer-ip-address: true

祖尔application.yml

server:
  port: 8080
spring:
  application:
    name: gatekeeper

zuul:
  routes:
    book: 
      serviceId: book

#Added it so as to increase the timeout for the underlying hysterix of the zuul

hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: THREAD
          thread:
            timeoutInMilliseconds: 60000

尤里卡服务器application.yml

server:
  port: 8761

eureka:
  client:
    register-with-eureka: false
    fetch-registry: false

Sring 云版本是动态的 ( ${spring-cloud.version}) 启动 2.1.0.release。

标签: javaspring-bootmicroservicesnetflix-eurekanetflix-zuul

解决方案


推荐阅读