【问题标题】:Hystrix circuit breaker doesn't pick the application.ymlHystrix 断路器不选择 application.yml
【发布时间】:2019-06-27 18:04:00
【问题描述】:

Hystrx 断路器不会从 application.yml 文件中选择值。我需要从 application.yml 文件中获取 timeoutInMilliseconds、errorThresholdPercentage。当我运行程序时,这些属性没有影响,因为它们没有被拾取。

import java.net.URI;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class BookService {
      RestTemplate restTemplate;
      //Calling the service
     @HystrixCommand
      public String readingList(int flag) {
        restTemplate = new RestTemplate();
         URI uri = URI.create("http://localhost:8090/recommended/"+flag);
        return this.restTemplate.getForObject(uri, String.class);
      }

      public String reliable(int flag) {
        return "Cloud Native Java (O'Reilly)";
      }

}

这是 application.yml 文件

hystrix:
  command:
    reliable:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 6000
          strategy: SEMAPHORE
        circuitBreaker:
          errorThresholdPercentage: 70

【问题讨论】:

    标签: spring-boot hystrix


    【解决方案1】:

    您需要使用 @HystrixCommand() 注释您的方法并给出 commandKey = "reliable"。

    @HystricCommand(commandKey="reliable")
    public String reliable(int flag) {
        return "Cloud Native Java (O'Reilly)";
      }
    

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 2018-10-05
      • 2018-07-09
      • 2017-05-29
      • 2016-12-11
      • 2016-08-06
      • 2015-12-06
      • 2015-06-19
      • 2016-01-11
      相关资源
      最近更新 更多