Class FluxAggregatorMessageHandler

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Lifecycle, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, ManageableLifecycle, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class FluxAggregatorMessageHandler extends AbstractMessageProducingHandler implements ManageableLifecycle
The AbstractMessageProducingHandler implementation for aggregation logic based on Reactor's Flux.groupBy(Function) and Flux.window(int) operators.

The incoming messages are emitted into a FluxSink provided by the Flux.create(Consumer) initialized in the constructor.

The resulting windows for groups are wrapped into Messages for downstream consumption.

If the AbstractMessageProducingHandler.getOutputChannel() is not a ReactiveStreamsSubscribableChannel instance, a subscription for the whole aggregating Flux is performed in the start() method.

With the default window size from the IntegrationMessageHeaderAccessor.SEQUENCE_SIZE header (and no setWindowTimespan(Duration)), a group is completed and its resources are released as soon as its window is closed. A later message with the same correlation key starts a new group. With all other window options, a group stays active for the whole lifetime of this handler, so they are better suited for a limited set of correlation keys.

A group failure (e.g. a missing or non-positive window size) is logged and only this group is discarded. A message for which the CorrelationStrategy returns null is rejected.

IMPORTANT: The IntegrationMessageHeaderAccessor.CORRELATION_ID and IntegrationMessageHeaderAccessor.SEQUENCE_SIZE headers are trusted by this handler. If messages come from untrusted sources, make sure such headers are not mapped from external messages, or configure an explicit CorrelationStrategy and window options.

Since:
5.2
Author:
Artem Bilan, Glenn Renfro