Share via


EventHubConsumerClient Class

Definition

A client responsible for reading EventData from a specific Event Hub as a member of a specific consumer group.

A consumer may be exclusive, which asserts ownership over associated partitions for the consumer group to ensure that only one consumer from that group is reading the from the partition. These exclusive consumers are sometimes referred to as "Epoch Consumers."

A consumer may also be non-exclusive, allowing multiple consumers from the same consumer group to be actively reading events from a given partition. These non-exclusive consumers are sometimes referred to as "Non-Epoch Consumers."

public class EventHubConsumerClient : IAsyncDisposable
type EventHubConsumerClient = class
    interface IAsyncDisposable
Public Class EventHubConsumerClient
Implements IAsyncDisposable
Inheritance
EventHubConsumerClient
Implements

Remarks

The EventHubConsumerClient is safe to cache and use for the lifetime of an application, which is the best practice when the application reads events regularly or semi-regularly. The consumer is responsible for ensuring efficient network, CPU, and memory use. Calling either CloseAsync(CancellationToken) or DisposeAsync() as the application is shutting down will ensure that network resources and other unmanaged objects are properly cleaned up.

Constructors

EventHubConsumerClient()

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, EventHubConnection, EventHubConsumerClientOptions)

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, String)

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, String, EventHubConsumerClientOptions)

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, String, String)

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, String, String, AzureNamedKeyCredential, EventHubConsumerClientOptions)

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, String, String, AzureSasCredential, EventHubConsumerClientOptions)

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, String, String, EventHubConsumerClientOptions)

Initializes a new instance of the EventHubConsumerClient class.

EventHubConsumerClient(String, String, String, TokenCredential, EventHubConsumerClientOptions)

Initializes a new instance of the EventHubConsumerClient class.

Fields

DefaultConsumerGroupName

The name of the default consumer group in the Event Hubs service.

Properties

ConsumerGroup

The name of the consumer group that this consumer is associated with. Events will be read only in the context of this group.

EventHubName

The name of the Event Hub that the consumer is connected to, specific to the Event Hubs namespace that contains it.

FullyQualifiedNamespace

The fully qualified Event Hubs namespace that the consumer is associated with. This is likely to be similar to {yournamespace}.servicebus.windows.net.

Identifier

A unique name used to identify this consumer.

IsClosed

Indicates whether or not this EventHubConsumerClient has been closed.

Methods

CloseAsync(CancellationToken)

Closes the consumer.

DisposeAsync()

Performs the task needed to clean up resources used by the EventHubConsumerClient, including ensuring that the client itself has been closed.

GetEventHubPropertiesAsync(CancellationToken)

Retrieves information about the Event Hub that the connection is associated with, including the number of partitions present and their identifiers.

GetPartitionIdsAsync(CancellationToken)

Retrieves the set of identifiers for the partitions of an Event Hub.

GetPartitionPropertiesAsync(String, CancellationToken)

Retrieves information about a specific partition for an Event Hub, including elements that describe the available events in the partition event stream.

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)

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.

ReadEventsFromPartitionAsync(String, EventPosition, CancellationToken)

Reads events from the requested partition 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 call the overload which accepts a set of options for configuring read behavior for scenarios where a more deterministic maximum waiting period is desired.

ReadEventsFromPartitionAsync(String, EventPosition, ReadEventOptions, CancellationToken)

Reads events from the requested partition 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.

Applies to