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
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleBatchingStrategy(int batchSize, int bufferLimit, long timeout)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable MessageBatch
    addToBatch(@Nullable String exch, @Nullable String routKey, org.springframework.amqp.core.Message message)
    Add a message to the batch and optionally release the batch.
    boolean
    canDebatch(org.springframework.amqp.core.MessageProperties properties)
    Return true if this strategy can decode a batch of messages from a message body.
    void
    deBatch(org.springframework.amqp.core.Message message, Consumer<org.springframework.amqp.core.Message> fragmentConsumer)
    Debatch a message that has a header with MessageProperties.SPRING_BATCH_FORMAT set to MessageProperties.BATCH_FORMAT_LENGTH_HEADER4.
    @Nullable Date
     
    Release batch(es), perhaps due to a timeout.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public @Nullable MessageBatch addToBatch(@Nullable String exch, @Nullable String routKey, org.springframework.amqp.core.Message message)
      Description copied from interface: BatchingStrategy
      Add a message to the batch and optionally release the batch.
      Specified by:
      addToBatch in interface BatchingStrategy
      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 @Nullable Date nextRelease()
      Specified by:
      nextRelease in interface BatchingStrategy
      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 interface BatchingStrategy
      Returns:
      The batched message(s).
    • canDebatch

      public boolean canDebatch(org.springframework.amqp.core.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 override BatchingStrategy.deBatch(Message, Consumer).
      Specified by:
      canDebatch in interface BatchingStrategy
      Parameters:
      properties - the message properties.
      Returns:
      true if we can decode the message.
      See Also:
    • deBatch

      public void deBatch(org.springframework.amqp.core.Message message, Consumer<org.springframework.amqp.core.Message> fragmentConsumer)
      Debatch a message that has a header with MessageProperties.SPRING_BATCH_FORMAT set to MessageProperties.BATCH_FORMAT_LENGTH_HEADER4.
      Specified by:
      deBatch in interface BatchingStrategy
      Parameters:
      message - the batched message.
      fragmentConsumer - a consumer for each fragment.
      Since:
      2.2
      See Also: