In the following example, test2
should be able to access the context
values from test
and test1
, but it seems like that is not happening.
Any insight is welcome.
References:
- http://projectreactor.io/docs/core/release/reference/#context
- https://jira.spring.io/browse/SPR-15680
https://simonbasle.github.io/2018/02/contextual-logging-with-reactor-context-and-mdc/.
import reactor.core.publisher.Mono; public class Test { public static void main(final String[] args) { System.out.println(Thread.currentThread().getName() + " main " + test()); } public static String test() { final String key = "message"; return test1().subscriberContext(ctx -> ctx.put(key, "test")).block(); } public static Mono<String> test1() { final String key = "message1"; return test2().subscriberContext(ctx -> ctx.put(key, "test1 ")); } public static Mono<String> test2() { return Mono.just("test2").map(item -> { Mono.subscriberContext().map(context -> { System.err.println(Thread.currentThread().getName() + " test2 " + context); return context; }); return item; }); }}
Output:
main main test2