Hystrix Context Aware
Switch branches/tags
Nothing to show
Clone or download


Hystrix Context Spring Boot starter

A Spring Boot starter for making Hystrix context aware

Build Status Coverage Status


Add the Spring Boot starter to your project:



Have you ever wondered why when running your Hystrix Commands the executing thread losses access to the ThreadLocal dependant functionality?

The simple answer is that by default Hystrix will spawn a new thread to execute your code, completely unaware of the "outer" thread context.

For instance fallowing code with fail with an exception because it's going to be executed in thread completely unaware of the Servlet request.

new HystrixCommand<Object>(commandKey()) {
    protected Object run() throws Exception {
        return RequestContextHolder.currentRequestAttributes().getAttribute("RequestId", SCOPE_REQUEST);

The same rules applies to your hystrix-javanica @HystrixCommand annotated methods.

This extension tries to solve this by allowing to register custom Callable wrappers that will be executed prior spawning new worker thread.


In order to use this feature all you need to do is register a instance of HystrixCallableWrapper. You may register as many of them as you like, they will be stacked up.


public class RequestAttributeAwareCallableWrapper implements HystrixCallableWrapper {

    public <T> Callable<T> wrapCallable(Callable<T> callable) {
        return new RequestAttributeAwareCallable<>(callable, RequestContextHolder.currentRequestAttributes());

    private static class RequestAttributeAwareCallable<T> implements Callable<T> {

        private final Callable<T> callable;
        private final RequestAttributes requestAttributes;

        public RequestAttributeAwareCallable(Callable<T> callable, RequestAttributes requestAttributes) {
            this.callable = callable;
            this.requestAttributes = requestAttributes;

        public T call() throws Exception {

            try {
                return callable.call();
            } finally {

This will make your Hystrix command aware of the execution context.


The only supported property is hystrix.wrappers.enabled which allows to disable this extension.

hystrix.wrappers.enabled=true # true by default


Apache 2.0