Is the order of adding events to an EventDataBatch also the order in which the events will be written to the eventhub?
Yes, when using the Azure Event Hubs Python SDK
, the order in which you add events to an EventDataBatch
is preserved when the batch is sent. This means that if you add events in a specific sequence, they will be sent to the Event Hub in that same order.
The EventDataBatch
class allows you to add events using the add method until the maximum batch size limit is reached. Once the batch is created and events are added, you can send the entire batch using the send_batch
method of the EventHubProducerClient
However, it's important to note that while the order is preserved within a single batch
, Azure Event Hubs does not guarantee the order of events across multiple batches or partitions. If maintaining the order of events is critical for your application, you should consider sending events to a specific partition by specifying a partition_id
or using a consistent partition_key.
This ensures that all related events are sent to the same partition, preserving their order.
Please refer the below Microsoft documentation for the more information
https://learn.microsoft.com/en-us/python/api/azure-eventhub/azure.eventhub.eventdatabatch?view=azure-python
https://learn.microsoft.com/en-us/python/api/azure-eventhub/azure.eventhub?view=azure-python
I hope this information helps. Please do let us know if you have any further queries.
Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues.
Thank you.