ServiceBusMessageBatch Class
A batch of messages.
Sending messages in a batch is more performant than sending individual message. ServiceBusMessageBatch helps you create the maximum allowed size batch of Message to improve sending performance.
Use the add method to add messages until the maximum batch size limit in bytes has been reached - at which point a MessageSizeExceededError will be raised.
Please use the create_message_batch method of ServiceBusSender to create a ServiceBusMessageBatch object instead of instantiating a ServiceBusMessageBatch object directly.
- Inheritance
-
builtins.objectServiceBusMessageBatch
Constructor
ServiceBusMessageBatch(max_size_in_bytes: int | None = None, **kwargs: Any)
Parameters
Name | Description |
---|---|
max_size_in_bytes
|
The maximum size of bytes data that a ServiceBusMessageBatch object can hold. Default value: None
|
Methods
add_message |
Try to add a single Message to the batch. The total size of an added message is the sum of its body, properties, etc. If this added size results in the batch exceeding the maximum batch size, a MessageSizeExceededError will be raised. |
add_message
Try to add a single Message to the batch.
The total size of an added message is the sum of its body, properties, etc. If this added size results in the batch exceeding the maximum batch size, a MessageSizeExceededError will be raised.
add_message(message: ServiceBusMessage | AmqpAnnotatedMessage | Mapping[str, Any]) -> None
Parameters
Name | Description |
---|---|
message
Required
|
The Message to be added to the batch. |
Exceptions
Type | Description |
---|---|
<xref:azure.servicebus.exceptions.MessageSizeExceededError>, <xref:when exceeding the size limit.>
|
Attributes
max_size_in_bytes
The maximum size of bytes data that a ServiceBusMessageBatch object can hold.
Returns
Type | Description |
---|---|
message
Get the underlying uamqp.BatchMessage or LegacyBatchMessage. This is deprecated and will be removed in a later release.
Returns
Type | Description |
---|---|
<xref:uamqp.BatchMessage>,
<xref:LegacyBatchMessage>
|
size_in_bytes
Azure SDK for Python