我正在学习Spring Cloud。
我们知道,如果远程配置文件已更新,则通过访问“ localhost:10000 / refresh”,我们可以在配置服务器上动态获取远程配置文件的自定义属性的值。我想问一下,如何将这些值动态注入Hystrix的注释中。
我的远程配置文件“ licenseservice.yml”,我将其放在git存储库中:
example.property:我是默认设置。我现在来自git。
example.timeoutInMilliseconds:12000
服务器: 端口:10000
尤里卡: 实例: preferred-ip-address:正确 ...
我用来获取配置文件中的值的java类:
@Component
@RefreshScope
public class ServiceConfig {
@Value("${example.property}")
private String exampleProperty;
@Value("${example.timeoutInMilliseconds}")
private String timeoutInMilliseconds;
public String getExampleProperty() {
return exampleProperty;
}
public String getTimeoutInMilliseconds(){
return timeoutInMilliseconds;
}
}
使用Hystrix批注的java方法:
@HystrixCommand(fallbackMethod = "buildFallbackLicenseList",
threadPoolKey = "licenseByOrgThreadPool",
threadPoolProperties = {
@HystrixProperty(name = "coreSize",value = "30"),
@HystrixProperty(name = "maxQueueSize", value = "10")
},
commandProperties = {
@HystrixProperty(name =
"circuitBreaker.requestVolumeThreshold",value = "10"),
@HystrixProperty(name =
"circuitBreaker.errorThresholdPercentage",value = "75"),
@HystrixProperty(name =
"circuitBreaker.sleepWindowInMilliseconds",value = "7000"),
@HystrixProperty(name =
"metrics.rollingStats.timeInMilliseconds",value = "15000"),
@HystrixProperty(name =
"metrics.rollingStats.numBuckets",value = "5"),
@HystrixProperty(name =
"execution.isolation.thread.timeoutInMilliseconds",value = ???)
})
public List<License> getLicensesByOrg(String organizationId){
System.out.println("SERVICE CONFIG TEST
"+serviceConfig.getExampleProperty());
System.out.println("SERVICE CONFIG TEST
"+serviceConfig.getTimeoutInMilliseconds());
randomlyRunLong();
return licenseRepository.findByOrganizationId(organizationId);
}
我的问题是,我想动态更改变量“ execution.isolation.thread.timeoutInMilliseconds”的值(通过使用.yml文件中的“ example.timeoutInMilliseconds”的值)。您可以看到我在那个地方写了三个问号,因为我不知道写什么,有人可以吗?告诉我,谢谢。