Interface BatchConsumer
- All Superinterfaces:
AutoCloseable, Consumer, EndpointAware, Service
A
Consumer that receives messages from an Endpoint in discrete batches rather than one at a time.
Batch consumers expose a setMaxMessagesPerPoll(int) limit to bound the number of messages fetched in a
single polling cycle, which helps control memory usage and startup latency.
During graceful shutdown, the ShutdownRunningTask option controls whether a batch in progress is completed in
full or interrupted after the current message.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether processing the batch is still allowed.intprocessBatch(Queue<Object> exchanges) Processes the list ofExchangeobjects in a batch.voidsetMaxMessagesPerPoll(int maxMessagesPerPoll) Sets a maximum number of messages as a limit to poll at each polling.Methods inherited from interface Consumer
createExchange, defaultConsumerCallback, getProcessor, releaseExchangeMethods inherited from interface EndpointAware
getEndpoint
-
Method Details
-
setMaxMessagesPerPoll
void setMaxMessagesPerPoll(int maxMessagesPerPoll) Sets a maximum number of messages as a limit to poll at each polling. Can be used to limit e.g. to 100 to avoid reading thousands or more messages within the first polling at startup. Is default unlimited, but use 0 or negative number to disable it as unlimited.- Parameters:
maxMessagesPerPoll- maximum messages to poll.
-
processBatch
Processes the list ofExchangeobjects in a batch. Each message exchange will be processed individually but the batch consumer will add properties with the current index and total in the batch. The items in the Queue may actually be Holder objects that store other data alongside the Exchange.- Parameters:
exchanges- list of items in this batch- Returns:
- number of messages actually processed
- Throws:
Exception- if an internal processing error has occurred.
-
isBatchAllowed
boolean isBatchAllowed()Whether processing the batch is still allowed. This is used during shutdown to indicate whether to complete the pending exchanges or stop after the current exchange has been processed.- Returns:
- true to continue processing from the batch, or false to stop.
- See Also:
-