From b1dd4669ed8760c28c05bb051ba3933b8127fb78 Mon Sep 17 00:00:00 2001
From: "Konstantin A. Zolotukhin"
- * Command execution timeout can be modified using application - * property redgreen.hystrix.simpleFailoverLine.commandTimeout ( note, a value should be defined in millis ). - *
- * * @since 0.1.0 */ public class HystrixSimpleFailoverLine implements FailoverLine { + /** + * Defines {@code Hystrix} command key, this constant can be used as the reference + * to this line execution command. + * + * @since 0.1.0 + */ + public static final String HYSTRIX_COMMAND_KEY = "SimpleFailoverLineExecution"; + // NOTE: ResourceHttpMessageConverter used to handle all possible content-types private RestTemplate restTemplate = new RestTemplate( Arrays.asList(new ResourceHttpMessageConverter()) @@ -65,12 +68,9 @@ public HystrixSimpleFailoverLine(RedgreenBundleRepostitory redgreenBundleReposti this.bundleRepostitory = redgreenBundleRepostitory; } - @HystrixCommand(fallbackMethod = "performFallback", + @HystrixCommand(commandKey=HYSTRIX_COMMAND_KEY, fallbackMethod = "performFallback", commandProperties = { - @HystrixProperty(name="circuitBreaker.enabled", - value="false"), - @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", - value="${redgreen.hystrix.simpleFailoverLine.commandTimeout}") + @HystrixProperty(name="circuitBreaker.enabled", value="false"), } ) @Override @@ -96,7 +96,7 @@ public Object performFallback(Supplier- * Note, in the version 0.1.0 it's only one possible {@link FailoverLine} - * configuration. + * Command execution timeout can be modified using application + * property redgreen.hystrix.simpleFailoverLine.commandTimeout ( note, a value should be defined in millis ). *
* *- * See {@link HystrixSimpleFailoverLine} documentaion for configuration properties details. + * See {@link HystrixSimpleFailoverLine} documentaion for implementation details. + *
+ * + *+ * Note, in the version 0.1.0 it's only one possible {@link FailoverLine} + * configuration. *
* * @see HystrixSimpleFailoverLine @@ -29,11 +36,27 @@ @Configuration public class HystrixSimpleFailoverLineConfiguration { + private static final String COMMAND_EXEC_TIMEOUT_PROPERTY = + "hystrix.command." + + HystrixSimpleFailoverLine.HYSTRIX_COMMAND_KEY + + ".execution.isolation.thread.timeoutInMilliseconds"; + @Autowired private RedgreenBundleRepostitory bundleRepostitory; + // TODO: extract to boot properties class + @Value("${redgreen.hystrix.simpleFailoverLine.commandTimeout:300}") + private String commandExecutionTimeout; + @Bean public HystrixSimpleFailoverLine simpleFailoverLine() { + + // NOTE: there are no another way to set values obtained from properties, + // hystrix-javanica does not support spring's properties placeholders atm + ConfigurationManager + .getConfigInstance() + .setProperty(COMMAND_EXEC_TIMEOUT_PROPERTY, commandExecutionTimeout); + return new HystrixSimpleFailoverLine(bundleRepostitory); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6f3eaa1..ff20b71 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ logging.level.ROOT=INFO -redgreen.hystrix.simpleFailoverLine.commandTimeout=900000 +redgreen.hystrix.simpleFailoverLine.commandTimeout=100 redgreen.direct.bundles.test-bundle.green=http://example.xcom/ redgreen.direct.bundles.test-bundle.red=http://example.com/ \ No newline at end of file