Class EventDataBatch
- Namespace
- Microsoft.ServiceBus.Messaging
- Assembly
- Microsoft.ServiceBus.dll
A helper class for creating a batch of EventData objects to be used for SendBatch or SendBatchAsync call.
public sealed class EventDataBatch : IDisposable
- Inheritance
-
EventDataBatch
- Implements
- Inherited Members
Constructors
EventDataBatch(long)
Creates a batch with the specified maximum size in bytes.
public EventDataBatch(long maxSizeInBytes)
Parameters
maxSizeInBytes
longThe maximum size of the serialized batch message.
Remarks
It is recommended to call CreateBatch() or CreateBatch() to create an instance of this class because it uses the maximum message size negotiated with the service. When the application creates a batch using the constructor, it is responsible to ensure the maxSizeInBytes is permitted by the service.
Properties
Count
Gets the current event count in the batch.
public int Count { get; }
Property Value
Methods
Dispose()
Disposes the EventData objects contained in this batch.
public void Dispose()
ToEnumerable()
Converts the batch to an IEnumerable of EventData objects that can be accepted by the SendBatch or SendBatchAsync method.
public IEnumerable<EventData> ToEnumerable()
Returns
- IEnumerable<EventData>
Returns an IEnumerable of EventData objects.
TryAdd(EventData)
Tries to add an event data to the batch if permitted by the batch's size limit.
public bool TryAdd(EventData eventData)
Parameters
Returns
- bool
A boolean value indicating if the event data has been added to the batch or not.
Remarks
This method checks the sizes of the batch, the EventData object and the specified limit to determine if the EventData object can be added. It does not perform other validations on the current batch and the EventData object. It is possible that the application may get exceptions from the send call if the batched EventData objects cannot be sent in a batch. For example, they contain different PartitionKey values.
Exceptions
- ArgumentNullException
Thrown when the EventData is null.
- ObjectDisposedException
Thrown when the batch is already disposed.