hystrix-context-spring-boot-starter

Spring Boot Hystrix Context

Лицензия

Лицензия

Категории

Категории

Spring Boot Контейнер Микросервисы
Группа

Группа

io.jmnarloch
Идентификатор

Идентификатор

hystrix-context-spring-boot-starter
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

hystrix-context-spring-boot-starter
Spring Boot Hystrix Context
Ссылка на сайт

Ссылка на сайт

https://github.com/jmnarloch/hystrix-context-spring-boot-starter
Система контроля версий

Система контроля версий

https://github.com/jmnarloch/hystrix-context-spring-boot-starter.git

Скачать hystrix-context-spring-boot-starter

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/io.jmnarloch/hystrix-context-spring-boot-starter/ -->
<dependency>
    <groupId>io.jmnarloch</groupId>
    <artifactId>hystrix-context-spring-boot-starter</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.jmnarloch/hystrix-context-spring-boot-starter/
implementation 'io.jmnarloch:hystrix-context-spring-boot-starter:1.0.0'
// https://jarcasting.com/artifacts/io.jmnarloch/hystrix-context-spring-boot-starter/
implementation ("io.jmnarloch:hystrix-context-spring-boot-starter:1.0.0")
'io.jmnarloch:hystrix-context-spring-boot-starter:jar:1.0.0'
<dependency org="io.jmnarloch" name="hystrix-context-spring-boot-starter" rev="1.0.0">
  <artifact name="hystrix-context-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.jmnarloch', module='hystrix-context-spring-boot-starter', version='1.0.0')
)
libraryDependencies += "io.jmnarloch" % "hystrix-context-spring-boot-starter" % "1.0.0"
[io.jmnarloch/hystrix-context-spring-boot-starter "1.0.0"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-configuration-processor Необязательный jar 1.3.5.RELEASE
org.springframework.boot : spring-boot-starter jar 1.3.5.RELEASE
com.netflix.hystrix : hystrix-core jar 1.5.3

test (4)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-web jar 1.3.5.RELEASE
org.springframework.boot : spring-boot-starter-test jar 1.3.5.RELEASE
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19

Модули Проекта

Данный проект не имеет модулей.

Hystrix Context Spring Boot starter

A Spring Boot starter for making Hystrix context aware

Build Status Coverage Status

Setup

Add the Spring Boot starter to your project:

<dependency>
  <groupId>io.jmnarloch</groupId>
  <artifactId>hystrix-context-spring-boot-starter</artifactId>
  <version>1.0.0</version>
</dependency>

Features

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()) {
    @Override
    protected Object run() throws Exception {
        return RequestContextHolder.currentRequestAttributes().getAttribute("RequestId", SCOPE_REQUEST);
    }
}.execute();

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.

Usage

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.

Example:

@Component
public class RequestAttributeAwareCallableWrapper implements HystrixCallableWrapper {

    @Override
    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;
        }

        @Override
        public T call() throws Exception {

            try {
                RequestContextHolder.setRequestAttributes(requestAttributes);
                return callable.call();
            } finally {
                RequestContextHolder.resetRequestAttributes();
            }
        }
    }
}

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

Properties

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

hystrix.wrappers.enabled=true # true by default

License

Apache 2.0

Версии библиотеки

Версия
1.0.0