Share via


EventHubConsumerClient.ReadEventsAsync Method

Definition

Overloads

ReadEventsAsync(CancellationToken)

Reads events from all partitions of the event hub as an asynchronous enumerable, allowing events to be iterated as they become available on the partition, waiting as necessary should there be no events available.

This enumerator may block for an indeterminate amount of time for an await if events are not available on the partition, requiring cancellation via the cancellationToken to be requested in order to return control. It is recommended to set the MaximumWaitTime for scenarios where a more deterministic maximum waiting period is desired.

ReadEventsAsync(ReadEventOptions, CancellationToken)

Reads events from all partitions of the event hub as an asynchronous enumerable, allowing events to be iterated as they become available on the partition, waiting as necessary should there be no events available.

This enumerator may block for an indeterminate amount of time for an await if events are not available on the partition, requiring cancellation via the cancellationToken to be requested in order to return control. It is recommended to set the MaximumWaitTime for scenarios where a more deterministic maximum waiting period is desired.

ReadEventsAsync(Boolean, ReadEventOptions, CancellationToken)

Reads events from all partitions of the event hub as an asynchronous enumerable, allowing events to be iterated as they become available on the partition, waiting as necessary should there be no events available.

This enumerator may block for an indeterminate amount of time for an await if events are not available on the partition, requiring cancellation via the cancellationToken to be requested in order to return control. It is recommended to set the MaximumWaitTime for scenarios where a more deterministic maximum waiting period is desired.

ReadEventsAsync(CancellationToken)

Source:
EventHubConsumerClient.cs
Source:
EventHubConsumerClient.cs

Reads events from all partitions of the event hub as an asynchronous enumerable, allowing events to be iterated as they become available on the partition, waiting as necessary should there be no events available.

This enumerator may block for an indeterminate amount of time for an await if events are not available on the partition, requiring cancellation via the cancellationToken to be requested in order to return control. It is recommended to set the MaximumWaitTime for scenarios where a more deterministic maximum waiting period is desired.

public virtual System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent> ReadEventsAsync (System.Threading.CancellationToken cancellationToken = default);
abstract member ReadEventsAsync : System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent>
override this.ReadEventsAsync : System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent>
Public Overridable Function ReadEventsAsync (Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of PartitionEvent)

Parameters

cancellationToken
CancellationToken

An optional CancellationToken instance to signal the request to cancel the operation.

Returns

An IAsyncEnumerable<T> to be used for iterating over events in the partition.

Exceptions

Occurs when an EventHubConsumerClient is unable to read from the Event Hub due to another reader having asserted exclusive ownership. In this case, the EventHubsException.FailureReason will be set to ConsumerDisconnected.

Remarks

This method is not recommended for production use; the EventProcessorClient should be used for reading events from all partitions in a production scenario, as it offers a much more robust experience with higher throughput.

It is important to note that this method does not guarantee fairness amongst the partitions during iteration; each of the partitions compete to publish events to be read by the enumerator. Depending on service communication, there may be a clustering of events per partition and/or there may be a noticeable bias for a given partition or subset of partitions.

Each reader of events is presented with an independent iterator; if there are multiple readers, each receive their own copy of an event to process, rather than competing for them.

See also

Applies to

ReadEventsAsync(ReadEventOptions, CancellationToken)

Source:
EventHubConsumerClient.cs
Source:
EventHubConsumerClient.cs

Reads events from all partitions of the event hub as an asynchronous enumerable, allowing events to be iterated as they become available on the partition, waiting as necessary should there be no events available.

This enumerator may block for an indeterminate amount of time for an await if events are not available on the partition, requiring cancellation via the cancellationToken to be requested in order to return control. It is recommended to set the MaximumWaitTime for scenarios where a more deterministic maximum waiting period is desired.

public virtual System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent> ReadEventsAsync (Azure.Messaging.EventHubs.Consumer.ReadEventOptions readOptions, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadEventsAsync : Azure.Messaging.EventHubs.Consumer.ReadEventOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent>
override this.ReadEventsAsync : Azure.Messaging.EventHubs.Consumer.ReadEventOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent>
Public Overridable Function ReadEventsAsync (readOptions As ReadEventOptions, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of PartitionEvent)

Parameters

readOptions
ReadEventOptions

The set of options to use for configuring read behavior; if not specified the defaults will be used.

cancellationToken
CancellationToken

An optional CancellationToken instance to signal the request to cancel the operation.

Returns

An IAsyncEnumerable<T> to be used for iterating over events in the partition.

Exceptions

Occurs when an EventHubConsumerClient is unable to read from the Event Hub due to another reader having asserted exclusive ownership. In this case, the EventHubsException.FailureReason will be set to ConsumerDisconnected.

Remarks

This method is not recommended for production use; the EventProcessorClient should be used for reading events from all partitions in a production scenario, as it offers a much more robust experience with higher throughput.

It is important to note that this method does not guarantee fairness amongst the partitions during iteration; each of the partitions compete to publish events to be read by the enumerator. Depending on service communication, there may be a clustering of events per partition and/or there may be a noticeable bias for a given partition or subset of partitions.

Each reader of events is presented with an independent iterator; if there are multiple readers, each receive their own copy of an event to process, rather than competing for them.

See also

Applies to

ReadEventsAsync(Boolean, ReadEventOptions, CancellationToken)

Source:
EventHubConsumerClient.cs
Source:
EventHubConsumerClient.cs

Reads events from all partitions of the event hub as an asynchronous enumerable, allowing events to be iterated as they become available on the partition, waiting as necessary should there be no events available.

This enumerator may block for an indeterminate amount of time for an await if events are not available on the partition, requiring cancellation via the cancellationToken to be requested in order to return control. It is recommended to set the MaximumWaitTime for scenarios where a more deterministic maximum waiting period is desired.

public virtual System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent> ReadEventsAsync (bool startReadingAtEarliestEvent, Azure.Messaging.EventHubs.Consumer.ReadEventOptions readOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadEventsAsync : bool * Azure.Messaging.EventHubs.Consumer.ReadEventOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent>
override this.ReadEventsAsync : bool * Azure.Messaging.EventHubs.Consumer.ReadEventOptions * System.Threading.CancellationToken -> System.Collections.Generic.IAsyncEnumerable<Azure.Messaging.EventHubs.Consumer.PartitionEvent>
Public Overridable Function ReadEventsAsync (startReadingAtEarliestEvent As Boolean, Optional readOptions As ReadEventOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As IAsyncEnumerable(Of PartitionEvent)

Parameters

startReadingAtEarliestEvent
Boolean

true to begin reading at the first events available in each partition; otherwise, reading will begin at the end of each partition seeing only new events as they are published.

readOptions
ReadEventOptions

The set of options to use for configuring read behavior; if not specified the defaults will be used.

cancellationToken
CancellationToken

An optional CancellationToken instance to signal the request to cancel the operation.

Returns

An IAsyncEnumerable<T> to be used for iterating over events in the partition.

Exceptions

Occurs when an EventHubConsumerClient is unable to read from the Event Hub due to another reader having asserted exclusive ownership. In this case, the EventHubsException.FailureReason will be set to ConsumerDisconnected.

Remarks

This method is not recommended for production use; the EventProcessorClient should be used for reading events from all partitions in a production scenario, as it offers a much more robust experience with higher throughput.

It is important to note that this method does not guarantee fairness amongst the partitions during iteration; each of the partitions competes to publish events to be read by the enumerator. Depending on service communication, there may be a clustering of events per partition and/or there may be a noticeable bias for a given partition or subset of partitions.

Each reader of events is presented with an independent iterator; if there are multiple readers, each receive their own copy of an event to process, rather than competing for them.

See also

Applies to