Class SimpleBatchingStrategy
- java.lang.Object
-
- org.springframework.amqp.rabbit.batch.SimpleBatchingStrategy
-
- All Implemented Interfaces:
BatchingStrategy
public class SimpleBatchingStrategy extends Object implements BatchingStrategy
A simple batching strategy that supports only one exchange/routingKey; includes a batch size, a batched message size limit and a timeout. The message properties from the first message in the batch is used in the batch message. Each message is preceded by a 4 byte length field.- Since:
- 1.4.1
- Author:
- Gary Russell
-
-
Constructor Summary
Constructors Constructor Description SimpleBatchingStrategy(int batchSize, int bufferLimit, long timeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageBatch
addToBatch(String exch, String routKey, Message message)
Add a message to the batch and optionally release the batch.boolean
canDebatch(MessageProperties properties)
Return true if this strategy can decode a batch of messages from a message body.void
deBatch(Message message, Consumer<Message> fragmentConsumer)
Debatch a message that has a header withMessageProperties.SPRING_BATCH_FORMAT
set toMessageProperties.BATCH_FORMAT_LENGTH_HEADER4
.Date
nextRelease()
Collection<MessageBatch>
releaseBatches()
Release batch(es), perhaps due to a timeout.
-
-
-
Method Detail
-
addToBatch
public MessageBatch addToBatch(String exch, String routKey, Message message)
Description copied from interface:BatchingStrategy
Add a message to the batch and optionally release the batch.- Specified by:
addToBatch
in interfaceBatchingStrategy
- Parameters:
exch
- The exchange.routKey
- The routing key.message
- The message.- Returns:
- The batched message (
MessageBatch
), or null if not ready to release.
-
nextRelease
public Date nextRelease()
- Specified by:
nextRelease
in interfaceBatchingStrategy
- Returns:
- the date the next scheduled release should run, or null if no data to release.
-
releaseBatches
public Collection<MessageBatch> releaseBatches()
Description copied from interface:BatchingStrategy
Release batch(es), perhaps due to a timeout.- Specified by:
releaseBatches
in interfaceBatchingStrategy
- Returns:
- The batched message(s).
-
canDebatch
public boolean canDebatch(MessageProperties properties)
Description copied from interface:BatchingStrategy
Return true if this strategy can decode a batch of messages from a message body. Returning true means you must overrideBatchingStrategy.deBatch(Message, Consumer)
.- Specified by:
canDebatch
in interfaceBatchingStrategy
- Parameters:
properties
- the message properties.- Returns:
- true if we can decode the message.
- See Also:
BatchingStrategy.deBatch(Message, Consumer)
-
deBatch
public void deBatch(Message message, Consumer<Message> fragmentConsumer)
Debatch a message that has a header withMessageProperties.SPRING_BATCH_FORMAT
set toMessageProperties.BATCH_FORMAT_LENGTH_HEADER4
.- Specified by:
deBatch
in interfaceBatchingStrategy
- Parameters:
message
- the batched message.fragmentConsumer
- a consumer for each fragment.- Since:
- 2.2
- See Also:
BatchingStrategy.canDebatch(MessageProperties)
-
-