南归北隐 2019-08-06 13:30 采纳率: 42.9%
浏览 1413
已采纳

zuul 超时 504,不触发服务熔断进行降级是为什么?

zuul 超时 504,不触发服务熔断进行降级是为什么?
图片说明
正常访问 http://localhost:8081/ribbon6 可以触发 Hystrix

网上说配置
##socket超时
zuul.host.socket-timeout-millis=3000
#HTTP连接超时要比Hystrix的大
zuul.host.connect-timeout-millis=10000

结果超时还是504 错误

    //服务熔断
    @HystrixCommand(fallbackMethod="helloFallback")
    public String helloService() throws InterruptedException {
        ResponseEntity<String> responseEntity = restTemplate.getForEntity("http://eureka-server/helloParam?username={1}", String.class, "didi");
        String body = responseEntity.getBody();
        //让处理线程等待几秒钟
        int sleepTime= new Random().nextInt(4000);
//      int sleepTime=3000;
        logger.info("sleepTime:" + sleepTime);
        Thread.sleep(sleepTime);
        logger.info("/hello, host:" + registration.getHost() + ", service id:" +registration.getServiceId());
        return body;    
    }


     //服务降级
     public String helloFallback() {
            return "error";
     }

消费者配置

#多实例配置
zuul.routes.hello-service.path=/hello-service/**
zuul.routes.hello-service.serviceId=hello-service
ribbon.eureka.enabled=false 
hello-service.ribbon.listOfServers=http://localhost:8080/,http://localhost:8082/
##socket超时
zuul.host.socket-timeout-millis=3000
#HTTP连接超时要比Hystrix的大
zuul.host.connect-timeout-millis=10000
  • 写回答

2条回答

  • 南归北隐 博客专家认证 2019-08-06 13:42
    关注

    解决了。。

    
    #单实例配置1 路由转发
    zuul.routes.eureka-server-1.path=/eureka-server-1/**
    zuul.routes.eureka-server-1.url=http://localhost:8080/
    #单实例配置2 路由转发
    zuul.routes.eureka-server-2.path=/eureka-server-2/**
    zuul.routes.eureka-server-2.url=http://localhost:8082/
    
    #多实例配置 负载均衡 路由转发
    zuul.routes.eureka-server-3.path=/eureka-server-3/**
    zuul.routes.eureka-server-3.serviceId=eureka-server
    eureka-server-3.ribbon.listOfServers=http://localhost:8080/,http://localhost:8082/
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!