我在使用Zuul和Ribbon时遇到问题。我还将Eureka用于微服务注册。
当我启动微服务生态系统并尝试使用功能区服务API(zuulservice:8761 / ribbon-service /)时,出现以下错误:
com.netflix.zuul.exception.ZuulException:转发错误 在org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:189)〜[spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:164)〜[spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:112)〜[spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:117)〜[zuul-core-1.3.1.jar:1.3.1] 在com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:193)〜[zuul-core-1.3.1.jar:1.3.1] 在com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157)〜[zuul-core-1.3.1.jar:1.3.1] 在com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:118)〜[zuul-core-1.3.1.jar:1.3.1] 在com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:96)〜[zuul-core-1.3.1.jar:1.3.1] 在com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:116)〜[zuul-core-1.3.1.jar:1.3.1] 在com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:81)〜[zuul-core-1.3.1.jar:1.3.1] 在org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:165)[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] 在org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequest(ZuulController.java:44)[spring-cloud-netflix-zuul-2.0.0.RELEASE.jar:2.0.0.RELEASE] 在org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52)[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)上[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)[spring-webmvc-5.0.5.RELEASE.jar:5.0.5.RELEASE] ............ .... 原因:com.netflix.client.ClientException:负载均衡器没有适用于客户端的服务器:功能区服务 在com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483)〜[ribbon-loadbalancer-2.2.5.jar:2.2.5] 在com.netflix.loadbalancer.reactive.LoadBalancerCommand $ 1.call(LoadBalancerCommand.java:184)〜[ribbon-loadbalancer-2.2.5.jar:2.2.5] 在com.netflix.loadbalancer.reactive.LoadBalancerCommand $ 1.call(LoadBalancerCommand.java:180)〜[ribbon-loadbalancer-2.2.5.jar:2.2.5] 在rx.Observable.unsafeSubscribe(Observable.java:10327)〜[rxjava-1.3.8.jar:1.3.8] 在rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:94)〜[rxjava-1.3.8.jar:1.3.8] 在rx.internal.operators.OnSubscribeConcatMap.call(OnSubscribeConcatMap.java:42)〜[rxjava-1.3.8.jar:1.3.8] 在rx.Observable.unsafeSubscribe(Observable.java:10327)〜[rxjava-1.3.8.jar:1.3.8]
此错误仍然存在一段时间,然后我得到以下输出:
2018-07-16 12:55:43.260信息19233 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty:翻转属性:ribbon-service.ribbon.ActiveConnections仅限使用NEXT属性:niws.loadbalancer。 AvailabilityFilteringRule.activeConnectionsLimit = 2147483647
输出之后,一切都会恢复正常。
当我点击eurekaservice:8765 / eureka / apps时,我已经注册了功能区服务和所有用户服务实例。
这是我的zuul服务application.properties:
> #Service port
server.port=8765
#Service port
spring.application.name=zuul-service
# Discovery Server Access
eureka.client.service-url.defaultZone:http://localhost:8761/eureka/
eureka.instance.lease-renewal-interval-in-seconds=3
#User service configuration
zuul.routes.user-service.path:/user-service/**
zuul.routes.user-service.serviceId:user-service
#Product service configuration
zuul.routes.product-service.path:/product-service/**
zuul.routes.product-service.serviceId:product-service
#Product service configuration
zuul.routes.shoppingcart-service.path:/shoppingcart-service/**
zuul.routes.shoppingcart-service.serviceId:shoppingcart-service
#Product service configuration
zuul.routes.payment-service.path:/payment-service/**
zuul.routes.payment-service.serviceId:payment-service
#Product service configuration
zuul.routes.ribbon-service.path:/ribbon-service/**
zuul.routes.ribbon-service.serviceId:ribbon-service
这是我的zuul服务bootstrap.properties:
> #Application name
spring.application.name=zuul-service
#hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 12600
ribbon.ConnectTimeout: 6000
ribbon.ReadTimeout: 60000
robbon.eureka.enabled: true
hystrix.command.default.execution.timeout.enabled=false
我正在使用spring 2.0.1和spring cloud Finchley.RELEASE。
有人可以解释发生了什么事吗?
谢谢!
答案 0 :(得分:0)
DiscoveryClient
的工作方式是,在每个Eureka
定义的时间段内,从hearbeat
(服务发现)中获取新的更改列表。在对注册应用程序进行的新更改从服务发现传播到您的Zuul实例之前,它一定会出现错误。
您在日志中看到的输出只是对它已收到此信息的确认。
答案 1 :(得分:0)
您可以考虑为zuul配置添加剥离路径配置。
在每个路由配置中添加stripPrefix = false