南归北隐 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条)

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)