Re: [HystrixOSS] How to configure Hystrix annotations

366 views
Skip to first unread message

Matt Jacobs

unread,
May 16, 2017, 2:28:55 PM5/16/17
to Brandon, HystrixOSS
Brandon - Can you open an issue on Github and cc @dmgcodevil?  We don't use any of the annotation support internally, so I don't have a great answer off the top of my head.  @dmgcodevil is the primary contributor to hystrix-javanica, and should be able to provide better assistance than me.

-Matt

On Thu, May 11, 2017 at 11:58 AM, Brandon <do...@live.ca> wrote:
I'm implementing a circuit breaker pattern with Hystrix. It seems to be working, but now I want to fetch certain Hystrix properties from my application properties with prefixes.

It looks like I should be using Archaius ConfigurationManager  but the wiki is all words and little code. This Q&A comes close but I don't understand their implementation (http://stackoverflow.com/questions/35085617/how-to-configure-hystrix-annotations-from-property-file).

My current circuit breaker looks like so:

   
@HystrixCommand(fallbackMethod = "enroll", commandProperties ={
       
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "650")
   
}
   
public ResponseEntity<byte[]> EnrollReq (params....){
       
//code
   
}

   
public ResponseEntity<byte[]> enroll(params...){
       
//return error status
   
}



I want to fetch the timeoutInMilliseconds from my application.properties which has this in it:

    Hystrix.Enroll.TimeoutInMilliseconds=650


I've created a specific class for HystrixCommandProperties:

    @ConfigurationProperties(prefix = "Hystrix.Enroll")
   
@Data
   
public class HystrixCommandProperties {
       
private int TimeoutInMilliseconds
   
}



I'm definitely missing some sort of connection between the stored spring configuration and the Hystrix syntax. I want the value = "650" in my circuit breaker to use the Hystrix.Enroll.TimeoutInMilliseconds instead.

--
You received this message because you are subscribed to the Google Groups "HystrixOSS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hystrixoss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shakir PM

unread,
May 24, 2017, 4:28:35 PM5/24/17
to HystrixOSS, do...@live.ca
I am also looking for same kind of implementation. Let me know if you are able to sortout. 

Thanks
To unsubscribe from this group and stop receiving emails from it, send an email to hystrixoss+...@googlegroups.com.

Brandon

unread,
May 25, 2017, 8:19:09 AM5/25/17
to HystrixOSS, do...@live.ca

Hey I ended up figuring it out. Basically making a POJO to take the variables from properties and apply them where they need to go.

Main Class:
@ControllerRuntimeProfiling(prefix = "enroll", logger = RequestLogger.class)    
@HystrixCommand(fallbackMethod = "enroll")

   
public ResponseEntity<byte[]> EnrollReq (params....){
       
//code
   
}

   
public ResponseEntity<byte[]> enroll(params...){

       
//return error status and logs
   
}

Hystrix Command Properties:
@Data
public class HystrixcommandProperties {

private int timeoutInMilli = 5000;
private int maxConReq = 200;

//logger if wanted

public HystrixCommandProperties init(String name){

ConfigurationManager.getConfigInstance().setProperty(String.format("hystrix.command.$s.excution.isolation.thread.timeout", name), timeoutInMilli);
//same for conreq

//logger if you want

return this;
}
}

HystrixConfig (Bean creation):
@Configuration
public class HystrixConfig {

@Bean
@ConfigurationProperties(prefix = "Hystrix.Enroll")
public HystrixCommandProperties enrollHystrixProperties(){
return new HystrixCommandProperties().init("processEnrollmentRequest");
}
//more beans here if needed

}

And then you also add the properties as required. Make sure to add them to staging and dev as well. The code was re-typed so I apologize for any typing mistakes.



Shakir PM

unread,
May 25, 2017, 9:26:04 AM5/25/17
to HystrixOSS, do...@live.ca
Thanks for reply. Just one question, 

what is $s in  String.format("hystrix.command.$s.excution.isolation.thread.timeout", name) ? And this is at global level or individual method level ? 

Brandon

unread,
May 25, 2017, 9:30:19 AM5/25/17
to HystrixOSS, do...@live.ca
Sorry that should be %s. The configuration manager handles the connections. I think it's method level. My variables are global in the properties file.
Reply all
Reply to author
Forward
0 new messages