该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
你需要用注释@HystrixCommand(你的方法),并给command键=“可靠”。
@HystricCommand(commandKey="reliable")
public String reliable(int flag) {
return "Cloud Native Java (O'Reilly)";
}