Class IntegrationReactiveUtils
- Since:
- 5.3
- Author:
- Artem Bilan, Fardan An
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationA default delay before repeating an empty sourceMonoas 1 secondDuration.static final StringThe subscriber context entry forFlux.delayElements(Duration)from theMono.repeatWhenEmpty(java.util.function.Function).static final booleanThe indicator thatio.micrometer:context-propagationlibrary is on classpath. -
Method Summary
Modifier and TypeMethodDescriptionstatic reactor.util.context.ContextViewCapture a ReactorContextViewfrom the current thread local state according to theContextSnapshotFactorylogic.static <T> reactor.core.publisher.Flux<Message<T>> messageChannelToFlux(MessageChannel messageChannel) Adapt a providedMessageChannelinto aFluxsource: - aFluxMessageChannelis returned as is because it is already aPublisher; - aSubscribableChannelis subscribed with aMessageHandlerfor theSinks.Many.tryEmitNext(Object)which is returned from this method; - aPollableChannelis wrapped into aIntegrationReactiveUtils.PollableChannelMessageSourceso cancelled in-flight receives can be re-queued, and reusesmessageSourceToFlux(MessageSource).static <T> reactor.core.publisher.Flux<Message<T>> messageSourceToFlux(MessageSource<T> messageSource) Wrap a providedMessageSourceinto aFluxfor pulling messages on demand.static @Nullable AutoCloseablesetThreadLocalsFromReactorContext(reactor.util.context.ContextView context) Populate thread local variables from the provided ReactorContextViewaccording to theContextSnapshotFactorylogic.
-
Field Details
-
DELAY_WHEN_EMPTY_KEY
The subscriber context entry forFlux.delayElements(Duration)from theMono.repeatWhenEmpty(java.util.function.Function).- See Also:
-
DEFAULT_DELAY_WHEN_EMPTY
-
isContextPropagationPresent
public static final boolean isContextPropagationPresentThe indicator thatio.micrometer:context-propagationlibrary is on classpath.- Since:
- 6.2.5
-
-
Method Details
-
captureReactorContext
public static reactor.util.context.ContextView captureReactorContext()Capture a ReactorContextViewfrom the current thread local state according to theContextSnapshotFactorylogic. If noio.micrometer:context-propagationlibrary is on classpath, theContext.empty()is returned.- Returns:
- the Reactor
ContextViewfrom the current thread local state orContext.empty(). - Since:
- 6.2.5
-
setThreadLocalsFromReactorContext
public static @Nullable AutoCloseable setThreadLocalsFromReactorContext(reactor.util.context.ContextView context) Populate thread local variables from the provided ReactorContextViewaccording to theContextSnapshotFactorylogic.- Parameters:
context- the ReactorContextViewto populate from.- Returns:
- the
ContextSnapshot.Scopeas aAutoCloseableto not pollute the target classpath. Can be cast if necessary. Or null if there is noio.micrometer:context-propagationlibrary is on classpath. - Since:
- 6.2.5
-
messageSourceToFlux
public static <T> reactor.core.publisher.Flux<Message<T>> messageSourceToFlux(MessageSource<T> messageSource) Wrap a providedMessageSourceinto aFluxfor pulling messages on demand. WhenMessageSource.receive()returnsnull, the sourceMonogoes to theMono.repeatWhenEmpty(Function)state and performs adelaybased on theDELAY_WHEN_EMPTY_KEYDurationentry in the subscriber context or falls back to 1-second duration. If a produced message has anIntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACKheader it is ack'ed inFlux.doOnNext(Consumer)when this flux emits to its subscriber, and nack'ed in theMono.doOnError(Consumer).Cancellation while
MessageSource.receive()is in flight (the sink is alreadyCANCELLED) is handled by Reactor's discard hook on this flux. Only aPollableChanneladapted throughmessageChannelToFlux(MessageChannel)is best-effort re-queued via non-blockingMessageChannel.send(Message, long)(interceptor chain is re-entered; FIFO is not preserved if the queue is not empty; a full bounded channel is logged and the message is not nack'd). A directmessageSourceToFlux(() -> channel.receive(0))lambda is not re-queued. Other sources are left unacknowledged so the source's own redelivery (broker requeue, uncommitted offset) can recover them. The discard hook only sees drops at or upstream of this flux; operators a caller adds afterward (ReactiveStreamsConsumer.setReactiveCustomizer, aflatMapon theReactiveMessageHandlerpath) use a different context and are not rescued here.- Type Parameters:
T- the expected payload type.- Parameters:
messageSource- theMessageSourceto adapt.- Returns:
- a
Fluxwhich pulls messages from theMessageSourceon demand.
-
messageChannelToFlux
public static <T> reactor.core.publisher.Flux<Message<T>> messageChannelToFlux(MessageChannel messageChannel) Adapt a providedMessageChannelinto aFluxsource: - aFluxMessageChannelis returned as is because it is already aPublisher; - aSubscribableChannelis subscribed with aMessageHandlerfor theSinks.Many.tryEmitNext(Object)which is returned from this method; - aPollableChannelis wrapped into aIntegrationReactiveUtils.PollableChannelMessageSourceso cancelled in-flight receives can be re-queued, and reusesmessageSourceToFlux(MessageSource).- Type Parameters:
T- the expected payload type.- Parameters:
messageChannel- theMessageChannelto adapt.- Returns:
- a
Fluxwhich uses a providedMessageChannelas a source for events to publish.
-