Class SimpleBatchingStrategy
java.lang.Object
org.springframework.amqp.rabbit.batch.SimpleBatchingStrategy
- All Implemented Interfaces:
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
-
Method Summary
Modifier and TypeMethodDescriptionaddToBatch
(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 a message that has a header withMessageProperties.SPRING_BATCH_FORMAT
set toMessageProperties.BATCH_FORMAT_LENGTH_HEADER4
.Release batch(es), perhaps due to a timeout.
-
Constructor Details
-
SimpleBatchingStrategy
public SimpleBatchingStrategy(int batchSize, int bufferLimit, long timeout) - Parameters:
batchSize
- the batch size.bufferLimit
- the max buffer size; could trigger a short batch. Does not apply to a single message.timeout
- the batch timeout.
-
-
Method Details
-
addToBatch
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
- Specified by:
nextRelease
in interfaceBatchingStrategy
- Returns:
- the date the next scheduled release should run, or null if no data to release.
-
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
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:
-
deBatch
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:
-