Package com.azure.messaging.servicebus
Class ServiceBusMessageBatch
java.lang.Object
com.azure.messaging.servicebus.ServiceBusMessageBatch
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 Summary
Modifier and TypeMethodDescriptionint
getCount()
Gets the number ofmessages
in the batch.int
Gets the maximum size, in bytes, of thebatch
.int
Gets the size of thebatch
in bytes.boolean
tryAddMessage
(ServiceBusMessage serviceBusMessage) Tries to add amessage
to the batch.
-
Method Details
-
getCount
public int getCount()Gets the number ofmessages
in the batch.- Returns:
- The number of
messages
in the batch.
-
getMaxSizeInBytes
public int getMaxSizeInBytes()Gets the maximum size, in bytes, of thebatch
.- Returns:
- The maximum size, in bytes, of the
batch
.
-
getSizeInBytes
public int getSizeInBytes()Gets the size of thebatch
in bytes.- Returns:
- The size of the
batch
in bytes.
-
tryAddMessage
Tries to add amessage
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
- TheServiceBusMessage
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
- ifmessage
isnull
.com.azure.core.amqp.exception.AmqpException
- ifmessage
is larger than the maximum size of theServiceBusMessageBatch
.
-