Class SimpleBatchingStrategy

  • All Implemented Interfaces:
    BatchingStrategy

    public class SimpleBatchingStrategy
    extends java.lang.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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      MessageBatch addToBatch​(java.lang.String exch, java.lang.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, java.util.function.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.
      java.util.Date nextRelease()  
      java.util.Collection<MessageBatch> releaseBatches()
      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 Detail

      • 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 Detail

      • addToBatch

        public MessageBatch addToBatch​(java.lang.String exch,
                                       java.lang.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 java.util.Date nextRelease()
        Specified by:
        nextRelease in interface BatchingStrategy
        Returns:
        the date the next scheduled release should run, or null if no data to release.
      • deBatch

        public void deBatch​(org.springframework.amqp.core.Message message,
                            java.util.function.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:
        BatchingStrategy.canDebatch(MessageProperties)