EventDataBatch Class

A batch of events.

Sending events in a batch is more performant than sending individual events. EventDataBatch helps you create the maximum allowed size batch of EventData to improve sending performance.

Use the add method to add events until the maximum batch size limit in bytes has been reached - at which point a ValueError will be raised. Use the send_batch method of EventHubProducerClient or the async EventHubProducerClient for sending.

Please use the create_batch method of EventHubProducerClient to create an EventDataBatch object instead of instantiating an EventDataBatch object directly.

WARNING: Updating the value of the instance variable max_size_in_bytes on an instantiated EventDataBatch object is HIGHLY DISCOURAGED. The updated max_size_in_bytes value may conflict with the maximum size of events allowed by the Event Hubs service and result in a sending failure.

Inheritance
builtins.object
EventDataBatch

Constructor

EventDataBatch(max_size_in_bytes: int | None = None, partition_id: str | None = None, partition_key: str | bytes | None = None, **kwargs: Any)

Parameters

Name Description
max_size_in_bytes
int

The maximum size of bytes data that an EventDataBatch object can hold.

Default value: None
partition_id
str

The specific partition ID to send to.

Default value: None
partition_key
str

With the given partition_key, event data will be sent to a particular partition of the Event Hub decided by the service.

Default value: None

Methods

add

Try to add an EventData to the batch.

The total size of an added event is the sum of its body, properties, etc. If this added size results in the batch exceeding the maximum batch size, a ValueError will be raised.

add

Try to add an EventData to the batch.

The total size of an added event is the sum of its body, properties, etc. If this added size results in the batch exceeding the maximum batch size, a ValueError will be raised.

add(event_data: EventData | AmqpAnnotatedMessage) -> None

Parameters

Name Description
event_data
Required

The EventData to add to the batch.

Returns

Type Description

Attributes

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

The combined size of the events in the batch, in bytes.

Returns

Type Description
int