Skip to content

Context Propagation

Nadim Benabdenbi edited this page May 22, 2018 · 2 revisions

Principle

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

Usage

@SpringBootApplication
@EnableContextPropagation
public class Application{
...
}

Configuration

Default configuration

ribbon.extensions.propagation.upStreamZone.enabled=true
ribbon.extensions.propagation.upStreamZone.key=upstream-zone

Minimal configuration

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

Disabling all propagation strategies

The propagation can be disabled for all component using

ribbon.extensions.propagation.enabled=false

Disabling specific strategies

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

Customization

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{
...
}