本文介绍了当实例关闭时,Spring cloud Zuul重试并转发到其他可用实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将"Camden.SR5"用于弹簧-云相关性,并使用弹簧靴"1.5.2.RELEASE".

using 'Camden.SR5' for spring-cloud-dependencies, with spring boot '1.5.2.RELEASE'.

在当前设置中,我有

  • eureka服务器
  • 配置服务器(在随机端口上运行)
  • zuul网关服务器
  • 和2个服务实例(在随机端口上运行)

所有这些实例均已成功向Eureka注册.

All these instances are successfully register with Eureka.

当所有服务都在运行时,可以通过zuul正确完成负载平衡.

When all the services are running, The load balancing is done properly through zuul without any issues.

实例被杀死时,Zuul仍在尝试使用关闭的同一服务来满足请求.但是,如果要等到关闭实例后获取eureka注册表,则其他实例"UP"将满足请求.

when an instance is killed, Zuul is still trying to fulfil the request using the same service which is down. However if waited till the eureka registry is fetched after shutting down the instance, requests are fulfilled with the other instances which are 'UP'.

    2017-03-07 19:57:41.409 DEBUG 26658 --- [nio-5555-exec-3] c.n.l.reactive.LoadBalancerCommand       : Got error org.apache.http.conn.HttpHostConnectException: Connect to 10.99.4.151:64381 [/10.99.4.151] failed: Connection refused when executed on server 10.99.4.151:64381
2017-03-07 19:57:41.420 DEBUG 26658 --- [nio-5555-exec-3] com.netflix.hystrix.AbstractCommand      : Error executing HystrixCommand.run(). Proceeding to fallback logic ...

com.netflix.client.ClientException: null
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:123) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:81) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.run(AbstractRibbonCommand.java:96) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.run(AbstractRibbonCommand.java:42) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]


    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ~[httpclient-4.5.3.jar:4.5.3]
    ... 162 common frames omitted

2017-03-07 19:57:41.425 DEBUG 26658 --- [nio-5555-exec-3] com.netflix.hystrix.AbstractCommand      : No fallback for HystrixCommand.

java.lang.UnsupportedOperationException: No fallback available.
    at com.netflix.hystrix.HystrixCommand.getFallback(HystrixCommand.java:292) [hystrix-core-1.5.6.jar:1.5.6]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.getFallback(AbstractRibbonCommand.java:117) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.getFallback(AbstractRibbonCommand.java:42) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]


at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_66]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_66]

2017-03-07 19:57:41.428  WARN 26658 --- [nio-5555-exec-3] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering

com.netflix.zuul.exception.ZuulException: Forwarding error
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:170) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:145) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:88) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]


以下是与@EnableZuulProxy和@EnableEurekaClient一起使用的zuul配置


Following are the zuul configuration used with @EnableZuulProxy and @EnableEurekaClient

    server:
  port: 5555

spring:
  application:
    name: gateway-server
  cloud:
    config:
      discovery:
        enabled: true
        service-id: CONFIGSERVER
      fail-fast: true
      retry:
        multiplier:  1.1
        initial-interval: 1000
        max-attempts: 6
        max-interval: 2000

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 100000
        timeout:
          enabled: false

ribbon:
  ReadTimeout: 5000
  ConnectTimeout: 3000
  maxAutoRetries: 1
  MaxAutoRetriesNextServer: 2
  OkToRetryOnAllOperations: true


logging:
  level:
    ROOT: DEBUG

zuul:
  routes:
    security-service:
      retryable: true


具有的两个服务实例都以唯一的实例ID运行


The 2 instances of service with are running with unique instance-ids

@EnableEurekaClient
@EnableHystrix
@SpringBootApplication
public class SecurityServer implements HealthIndicator{

    public static void main(String args[])
    {
        SpringApplication.run(SecurityServer.class,args);
    }

    @Override
    public Health health() {
        return Health.up().withDetail("STATUS", "SUCCESS").build();
    }
}


instanceId: ${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.uuid}}


您能帮我祖尔&吗?实例配置,这样当实例发生故障时,请求会自动转发到其他可用实例.


Can you help me with the zuul & instances configuration, so that request is automatically forwarded to the other available instances when an instance goes down.

推荐答案

在进一步研究并调查spring-cloud-netflix问题跟踪器之后,在 william-tran ryanjbaxter 最好实践.谢谢你们.

upon searching out more and looking into spring-cloud-netflix issue tracker, There is a wonderful discussion between william-tran and ryanjbaxter on the best practices. Thanks to both of you.

https://github.com/spring -cloud/spring-cloud-netflix/issues/1290#issuecomment-242204614

https://github.com/spring-cloud/spring -cloud-netflix/issues/1295

总而言之,Camden不使用Ribbon HTTP Client(不建议使用),因此,ribbon.*属性均不会帮助您控制重试逻辑. Camden使用Apache HTTP客户端.

In summary, Camden doesn't use the Ribbon HTTP Client(deprecated) so none of the ribbon.* properties will help you control the retry logic. Camden uses Apache HTTP client.

因此解决方案将是使用以下配置在camden版本中使用Ribbon HTTP Client

So the solution would be to use Ribbon HTTP Client in camden version using below configuration

ribbon.restclient.enabled=true

移动到Camden.BUILD-SNAPSHOT或Dalston.BUILD-SNAPSHOT以使用spring-retry( https://github.com/spring-projects/spring-retry )

Move to Camden.BUILD-SNAPSHOT or Dalston.BUILD-SNAPSHOT for using spring-retry (https://github.com/spring-projects/spring-retry)

这篇关于当实例关闭时,Spring cloud Zuul重试并转发到其他可用实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:43