-
Notifications
You must be signed in to change notification settings - Fork 16
Context Propagation
The context propagation comes with default strategies for Histrix, Zuul, Feign, spring & java executors, http request, jms, stomp.
The default strategies will preserves the execution context within any async call and will propagate this execution context to downstream services using Http Headers, Stomp Headers or Jms message properties.
- http request default strategy copies desired http headers to the current execution context.
- feign strategy copies current execution context to the http headers.
- executor strategy copies the current execution context to the thread local of the target executor thread.
- zuul strategy defines a custom copies desired http headers to the current execution context.
- hystrix zuul strategy defines a custom plugin that preserves the execution context.
- jms strategy copies the current execution context to the jms headers.
- stomp strategy copies the current execution context to the stomp headers,
❗ The context propagation shares by default the current zone with down stream services (which is highly recommended when enabling the favorite zone). ❗ when dealing with http propagation it is highly recommended to use
@SpringBootApplication
@EnableContextPropagation
public class Application{
...
}
ribbon.extensions.propagation.upStreamZone.enabled=true
ribbon.extensions.propagation.upStreamZone.key=upstream-zone
Should set at least the propagation keys (by default it is empty).
ribbon.extensions.propagation.keys[0]=upstream-zone
ribbon.extensions.propagation.keys[1]=favorite-zone
The propagation can be disabled for all component using
ribbon.extensions.propagation.enabled=false
Programmatically
@SpringBootApplication
@EnableContextPropagation(
inboundHttpRequest=false,
feign=false,
executor=false,
zuul=false,
hystrix=false,
jms=false,
stomp=false,
public class Application{
...
}
Using properties
ribbon.extensions.propagation.inboundHttpRequest.enabled=false
ribbon.extensions.propagation.feign.enabled=false
ribbon.extensions.propagation.executor.enabled=false
ribbon.extensions.propagation.zuul.enabled=false
ribbon.extensions.propagation.hystrix.enabled=false
ribbon.extensions.propagation.jms.enabled=false
ribbon.extensions.propagation.stomp.enabled=false
The propagation strategy can be configured at component level.
Default strategies are defined within the annotation @EnableContextPropagation itself
To use custom strategy simply override default ones.
Example:
@SpringBootApplication
@EnableContextPropagation(
inboundHttpRequestStrategy=YourCustomInboundHttpRequestStrategy.class,
feignStrategy=YourCustomFeignStrategy.class,
executorStrategy=YourCustomExecutorStrategy.class,
zuulStrategy=YourCustomZuulStrategy.class,
hystrixStrategy=YourCustomHystrixStrategy.class,
jmsStrategy=YourCustomJmsStrategy.class,
stompStrategy=YourCustomStompStrategy.class,
public class Application{
...
}