Last active
January 10, 2023 02:18
-
-
Save jei0486/edc727ccc81819314411507253f1637f to your computer and use it in GitHub Desktop.
MDC with webflux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @link https://www.novatec-gmbh.de/en/blog/how-can-the-mdc-context-be-used-in-the-reactive-spring-applications/ | |
* https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Hooks.html#onEachOperator-java.util.function.Function- | |
*/ | |
@Configuration | |
public class MdcContextLifterConfig { | |
public static final String MDC_CONTEXT_REACTOR_KEY = MdcContextLifterConfig.class.getName(); | |
@PostConstruct | |
@SuppressWarnings("unchecked") | |
public void contextOperatorHook() { | |
Hooks.onEachOperator( | |
MDC_CONTEXT_REACTOR_KEY, | |
Operators.lift((scannable, subscriber) -> new MdcContextLifter(subscriber))); | |
} | |
@PreDestroy | |
public void cleanupHook() { | |
Hooks.resetOnEachOperator(MDC_CONTEXT_REACTOR_KEY); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment