Class ServiceBusMessageBatch

java.lang.Object
com.azure.messaging.servicebus.ServiceBusMessageBatch

public final class ServiceBusMessageBatch extends Object
A class for aggregating messages into a single, size-limited, batch. It is treated as a single AMQP message when sent to the Azure Service Bus service.
  • Method Details

    • getCount

      public int getCount()
      Gets the number of messages in the batch.
      Returns:
      The number of messages in the batch.
    • getMaxSizeInBytes

      public int getMaxSizeInBytes()
      Gets the maximum size, in bytes, of the batch.
      Returns:
      The maximum size, in bytes, of the batch.
    • getSizeInBytes

      public int getSizeInBytes()
      Gets the size of the batch in bytes.
      Returns:
      The size of the batch in bytes.
    • tryAddMessage

      public boolean tryAddMessage(ServiceBusMessage serviceBusMessage)
      Tries to add a message to the batch.

      This method is not thread-safe; make sure to synchronize the method access when using multiple threads to add messages.

      Parameters:
      serviceBusMessage - The ServiceBusMessage to add to the batch.
      Returns:
      true if the message could be added to the batch; false if the event was too large to fit in the batch.
      Throws:
      NullPointerException - if message is null.
      com.azure.core.amqp.exception.AmqpException - if message is larger than the maximum size of the ServiceBusMessageBatch.