Class EventDataBatch

java.lang.Object
com.azure.messaging.eventhubs.EventDataBatch

public final class EventDataBatch extends Object
A class for aggregating EventData into a single, size-limited, batch. It is treated as a single message when sent to the Azure Event Hubs service. EventDataBatch is recommended in scenarios requiring high throughput for publishing events.
See Also:
  • Method Details

    • getCount

      public int getCount()
      Gets the number of events in the batch.
      Returns:
      The number of events in the batch.
    • getMaxSizeInBytes

      public int getMaxSizeInBytes()
      Gets the maximum size, in bytes, of the EventDataBatch.
      Returns:
      The maximum size, in bytes, of the EventDataBatch.
    • getSizeInBytes

      public int getSizeInBytes()
      Gets the size of the EventDataBatch in bytes.
      Returns:
      the size of the EventDataBatch in bytes.
    • tryAdd

      public boolean tryAdd(EventData eventData)
      Tries to add an event to the batch.

      This method is not thread-safe; make sure to synchronize the method access when using multiple threads to add events.

      When batch was create with partition key, the event data will be updated with this partition key.

      Parameters:
      eventData - The EventData to add to the batch.
      Returns:
      true if the event could be added to the batch; false if the event was too large to fit in the batch, to accommodate the event, the application should obtain a new EventDataBatch object and add event to it.
      Throws:
      IllegalArgumentException - if eventData is null.
      com.azure.core.amqp.exception.AmqpException - if eventData is larger than the maximum size of the EventDataBatch.