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