Search code examples
springspring-cloudhystrixspring-cloud-netflixnetflix-feign

How to set set a HystrixProperty to a Feign request with spring cloud?


According to the documentation, when using Feign with Hystrix every request is wrap into a Hystrix command.

Is it possible to set Hystrix Properties to these commands? I'd like to do something like this:

@RequestMapping(commandProperties = {
    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000")})
List<Team> findAll();

or:

@FeignClient(name = "teams", commandProperties = {
    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000")})

For the records, I've already tried to use properties but it didn't work. These ones are working:

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000
hystrix.command.findAll.execution.timeout.enabled=false
hystrix.command.default.execution.timeout.enabled=false

But this one does not:

hystri‌​x.command.findAll.ex‌​ecution.isolation.thread.timeoutInMillis‌​econds=20000

Indeed, we can read the following comment into the HystrixCommandProperties class:

    //this property name is now misleading.  //TODO figure out a good way to deprecate this property name
    this.executionTimeoutInMilliseconds = getProperty(propertyPrefix, key, "execution.isolation.thread.timeoutInMilliseconds", builder.getExecutionIsolationThreadTimeoutInMilliseconds(), default_executionTimeoutInMilliseconds);

EDIT: I have tried to use the feign' Request.Option but these properties doesn't seem to propagate to hystrix.


Solution

  • Problem solved: it was an encoding issue. I had copied/pasted a line from the documentation, but it wasn't UTF-8 encoded (although STS' display was correct).