Class MonoUtils
monos.- Since:
- 5.0.0
- Author:
- John Hendrikx
-
Method Summary
Modifier and TypeMethodDescriptionstatic <M extends Message>
MessageStream.Single<M> asSingle(reactor.core.publisher.Mono<M> mono) static <M extends Message>
MessageStream.Single<M>
-
Method Details
-
asSingle
public static <M extends Message> MessageStream.Single<M> asSingle(reactor.core.publisher.Mono<M> mono) Create a stream that returns a singleentrywrapping theMessagefrom the givenmono, once it completes.The stream will contain at most a single entry. It may also contain no entries if the mono completes empty. The stream will complete with an exception when the given
monocompletes exceptionally.The given
monois subscribed withThreadLocal context capture:Mono.toFuture()subscribes with a context-lessCoreSubscriber, so without an explicit capture the mono's ReactorContextwould always be empty, and thread-bound state present at subscription -- such as the tracing span and observation a message handler runs under -- could never reach the mono's operators or context-reading instrumentation (for example Spring Boot's R2DBC observation) downstream. -
asSingle
public static <M extends Message> MessageStream.Single<M> asSingle(reactor.core.publisher.Mono<M> mono, Function<M, Context> contextSupplier) Create a stream that returns a singleentrywrapping theMessagefrom the givenmono, once it completes.The automatically generated
Entrywill have theContextas given by thecontextSupplier.The stream will contain at most a single entry. It may also contain no entries if the mono completes empty. The stream will complete with an exception when the given
monocompletes exceptionally.The given
monois subscribed withThreadLocal context capture-- seeasSingle(Mono)for the rationale.- Type Parameters:
M- the type ofMessagecontained in theentriesof this stream- Parameters:
mono- theMonoproviding theMessageto contain in the streamcontextSupplier- aFunctioningesting theMessagefrom the givenmonoreturning theContextto set for theMessageStream.EntrytheMessageis wrapped in- Returns:
- a stream containing at most one
entryfrom the givenmono
-