gpt4 book ai didi

spring-cloud - 当实例关闭并转发到其他可用实例时,Spring Cloud Zuul 重试

转载 作者:行者123 更新时间:2023-12-04 15:19:10 25 4
gpt4 key购买 nike

使用“Camden.SR5”作为sp​​ring-cloud-dependencies,使用spring boot '1.5.2.RELEASE'。

在我目前的设置中,我有

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

  • 所有这些实例都成功注册到 Eureka。

    enter image description here

    当所有服务都在运行时,负载均衡通过 zuul 正确完成,没有任何问题。

    当一个实例被杀死时,Zuul 仍在尝试使用已关闭的相同服务来满足请求。但是,如果等到关闭实例后获取 eureka 注册表,则其他“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 配置
        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

    服务的 2 个实例使用唯一的实例 ID 运行
    @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}}

    你能帮我配置 zuul 和实例吗,这样当一个实例出现故障时,请求会自动转发到其他可用的实例。

    最佳答案

    在搜索更多并查看 spring-cloud-netflix 问题跟踪器后,william-tran 之间进行了精彩的讨论。和 ryanjbaxter关于最佳实践。感谢你们俩。

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

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

    总之,Camden 不使用功能区 HTTP 客户端(已弃用),因此所有功能区.* 属性都不会帮助您控制重试逻辑。 Camden 使用 Apache HTTP 客户端。

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

    ribbon.restclient.enabled=true

    或者

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

    关于spring-cloud - 当实例关闭并转发到其他可用实例时,Spring Cloud Zuul 重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42651456/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com