如何从 属性 文件配置 Hystrix 注释?
How to configure Hystrix annotations from property file?
我使用 Hystrix-Java 库通过注释应用断路器。我想使用 Spring 配置中定义的属性来配置 Hystrix。因为我的应用程序使用 Spring AOP,所以我希望这样的事情会起作用:
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "${cb.requestVolumeThreshold}")
})
public boolean checkWebservice(String id) { ... }
但这失败了 bad property value. property name 'circuitBreaker.requestVolumeThreshold'. Expected int value
关于如何在不对值进行硬编码的情况下配置 Hystrix 的任何想法?
在 Hystrix 注释中使用 属性 占位符无效。
相反,我选择定义完整的配置属性,例如:
hystrix.command.checkWebservice.circuitBreaker.requestVolumeThreshold=10
并且我添加了此 Spring 配置 class 以将 spring 属性加载到 Archaius:
@Configuration
public class HystrixConfig {
@Autowired
private CommonsConfigurationFactoryBean props;
@PostConstruct
public void init() {
ConfigurationManager.install(props.getConfiguration());
}
}
Spring Cloud Netflix 可能是此设置的替代方案,但它需要 Spring Boot。
我使用 Hystrix-Java 库通过注释应用断路器。我想使用 Spring 配置中定义的属性来配置 Hystrix。因为我的应用程序使用 Spring AOP,所以我希望这样的事情会起作用:
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "${cb.requestVolumeThreshold}")
})
public boolean checkWebservice(String id) { ... }
但这失败了 bad property value. property name 'circuitBreaker.requestVolumeThreshold'. Expected int value
关于如何在不对值进行硬编码的情况下配置 Hystrix 的任何想法?
在 Hystrix 注释中使用 属性 占位符无效。
相反,我选择定义完整的配置属性,例如:
hystrix.command.checkWebservice.circuitBreaker.requestVolumeThreshold=10
并且我添加了此 Spring 配置 class 以将 spring 属性加载到 Archaius:
@Configuration
public class HystrixConfig {
@Autowired
private CommonsConfigurationFactoryBean props;
@PostConstruct
public void init() {
ConfigurationManager.install(props.getConfiguration());
}
}
Spring Cloud Netflix 可能是此设置的替代方案,但它需要 Spring Boot。