如何使用 reactor 在 doFinally 或 doOnCancel 中获取上下文?
How can I get the context in doFinally or doOnCancel with reactor?
我正在尝试获取上下文中的值,但我不知道该怎么做,知道吗?例如:
return mono
.doFinally(signalType -> how??? )
.doOnEach(signal -> {
... signal.getContext();
...
}) -> is ok I got the context
.subscriberContext(ctx -> ctx.put("key", "foo"));
考虑使用 Mono#deferWithContext
:
return Mono
.deferWithContext(ctx -> {
mono.doFinally(signalType -> handleSignal(ctx, signalType))
.doOnEach(...)
})
// later...
.subscriberContext(ctx -> ctx.put("key", "foo"));
我正在尝试获取上下文中的值,但我不知道该怎么做,知道吗?例如:
return mono
.doFinally(signalType -> how??? )
.doOnEach(signal -> {
... signal.getContext();
...
}) -> is ok I got the context
.subscriberContext(ctx -> ctx.put("key", "foo"));
考虑使用 Mono#deferWithContext
:
return Mono
.deferWithContext(ctx -> {
mono.doFinally(signalType -> handleSignal(ctx, signalType))
.doOnEach(...)
})
// later...
.subscriberContext(ctx -> ctx.put("key", "foo"));