com.netflix.zuul.exception.ZuulException:Hystrix读取超时504

时间:2019-08-07 05:47:33

标签: java netflix-zuul hystrix

在之后添加zuul。

配置

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=3000

请求控制器

@HystrixCommand(fallbackMethod="helloFallback")
  

无效

     

页面

     

com.netflix.zuul.exception.ZuulException:Hystrix读取超时504错误

application.properties

    eureka.client.service-url.defaultZone=http://127.0.0.1:8080/eureka,http://127.0.0.1:8082/eureka
    spring.application.name=hello-service
    server.port=8081
    management.context-path=/
    spring.cloud.loadbalancer.retry.enabled=true
    hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=3000
    hello-service.ribbon.ConnectTimeout=250
    hello-service.ribbon.OkToRetryOnAllOperations=true
    hello-service.ribbon.MaxAutoRetriesNextServer=2
    hello-service.ribbon.MaxAutoRetries=1
    management.endpoints.web.exposure.include=*
    management.endpoints.web.exposure.exclude=env,beans
    feign.compression.request.enabled=true
    feign.compression.response.enabled=true
    feign.compression.request.mime-types=text/xml,application/xml,application/json
    feign.compression.request.min-request-size=2048
    logging.level.com.kero99.service.ConsumerService=DEBUG
    zuul.routes.hello-service.path=/hello-service/**
    zuul.routes.hello-service.serviceId=hello-service
    hello-service.ribbon.listOfServers=http://localhost:8080/,http://localhost:8082/
    zuul.host.socket-timeout-millis=60000
    zuul.host.connect-timeout-millis=10000

HelloServiceImpl.java

@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);
    logger.info("sleepTime:" + sleepTime);
    Thread.sleep(sleepTime);
    logger.info("/hello, host:" + registration.getHost() + ", service id:" +registration.getServiceId());
    return body;    
}


 public String helloFallback() {
        return "error";
 }

现在页面显示

  

com.netflix.zuul.exception.ZuulException:Hystrix读取超时504

我要fallbackMethod返回“错误”;

MS Docs Reference

0 个答案:

没有答案