EventProcessorClient Class

Definition

Allows for consuming and processing events across all partitions of a given Event Hub within the scope of a specific consumer group.  The processor is capable of collaborating with other instances for the same Event Hub and consumer group pairing to share work by using a common storage platform to communicate.  Fault tolerance is also built-in, allowing the processor to be resilient in the face of errors.

public class EventProcessorClient : Azure.Messaging.EventHubs.Primitives.EventProcessor<Azure.Messaging.EventHubs.Primitives.EventProcessorPartition>
type EventProcessorClient = class
    inherit EventProcessor<EventProcessorPartition>
Public Class EventProcessorClient
Inherits EventProcessor(Of EventProcessorPartition)
Inheritance

Remarks

The EventProcessorClient is safe to cache and use for the lifetime of an application, and that is best practice when the application processes events regularly or semi-regularly. The processor holds responsibility for efficient resource management, working to keep resource usage low during periods of inactivity and manage health during periods of higher use. Calling either the StopProcessingAsync(CancellationToken) or StopProcessing(CancellationToken) method when processing is complete or as the application is shutting down will ensure that network resources and other unmanaged objects are properly cleaned up.

Constructors

EventProcessorClient()

Initializes a new instance of the EventProcessorClient class.

EventProcessorClient(BlobContainerClient, String, String)

Initializes a new instance of the EventProcessorClient class.

EventProcessorClient(BlobContainerClient, String, String, EventProcessorClientOptions)

Initializes a new instance of the EventProcessorClient class.

EventProcessorClient(BlobContainerClient, String, String, String)

Initializes a new instance of the EventProcessorClient class.

EventProcessorClient(BlobContainerClient, String, String, String, EventProcessorClientOptions)

Initializes a new instance of the EventProcessorClient class.

EventProcessorClient(BlobContainerClient, String, String, String, TokenCredential, EventProcessorClientOptions)

Initializes a new instance of the EventProcessorClient class.

Properties

ConsumerGroup

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

EventHubName

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

FullyQualifiedNamespace

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

Identifier

A unique name used to identify this event processor.

IsRunning

Indicates whether or not this event processor is currently running.

RetryPolicy

The active policy which governs retry attempts for the processor.

(Inherited from EventProcessor<TPartition>)

Methods

ClaimOwnershipAsync(IEnumerable<EventProcessorPartitionOwnership>, CancellationToken)

Attempts to claim ownership of the specified partitions for processing. This method is used by load balancing to allow event processor instances to distribute the responsibility for processing partitions for a given Event Hub and consumer group pairing amongst the active event processors.

CreateConnection()

Creates an EventHubConnection to use for communicating with the Event Hubs service.

ListCheckpointsAsync(CancellationToken)

Produces a list of the available checkpoints for the Event Hub and consumer group associated with the event processor instance, so that processing for a given set of partitions can be properly initialized.

ListOwnershipAsync(CancellationToken)

Produces a list of the ownership assignments for partitions between each of the cooperating event processor instances for a given Event Hub and consumer group pairing. This method is used when load balancing to allow the processor to discover other active collaborators and to make decisions about how to best balance work between them.

OnInitializingPartitionAsync(EventProcessorPartition, CancellationToken)

Performs the tasks to initialize a partition, and its associated context, for event processing.

OnInitializingPartitionAsync(TPartition, CancellationToken)

Performs the tasks to initialize a partition, and its associated context, for event processing.

(Inherited from EventProcessor<TPartition>)
OnPartitionProcessingStoppedAsync(EventProcessorPartition, ProcessingStoppedReason, CancellationToken)

Performs the tasks needed when processing for a partition is being stopped. This commonly occurs when the partition is claimed by another event processor instance or when the current event processor instance is shutting down.

OnPartitionProcessingStoppedAsync(TPartition, ProcessingStoppedReason, CancellationToken)

Performs the tasks needed when processing for a partition is being stopped. This commonly occurs when the partition is claimed by another event processor instance or when the current event processor instance is shutting down.

(Inherited from EventProcessor<TPartition>)
OnProcessingErrorAsync(Exception, EventProcessorPartition, String, CancellationToken)

Performs the tasks needed when an unexpected exception occurs within the operation of the event processor infrastructure.

OnProcessingErrorAsync(Exception, TPartition, String, CancellationToken)

Performs the tasks needed when an unexpected exception occurs within the operation of the event processor infrastructure.

(Inherited from EventProcessor<TPartition>)
OnProcessingEventBatchAsync(IEnumerable<EventData>, EventProcessorPartition, CancellationToken)

Performs the tasks needed to process a batch of events for a given partition as they are read from the Event Hubs service.

OnProcessingEventBatchAsync(IEnumerable<EventData>, TPartition, CancellationToken)

Performs the tasks needed to process a batch of events for a given partition as they are read from the Event Hubs service.

(Inherited from EventProcessor<TPartition>)
ReadLastEnqueuedEventProperties(String)

A set of information about the last enqueued event of a partition, as observed by the associated EventHubs client associated with this context as events are received from the Event Hubs service. This is only available if the consumer was created with TrackLastEnqueuedEventProperties set.

(Inherited from EventProcessor<TPartition>)
StartProcessing(CancellationToken)

Signals the EventProcessorClient to begin processing events. Should this method be called while the processor is running, no action is taken.

StartProcessingAsync(CancellationToken)

Signals the EventProcessorClient to begin processing events. Should this method be called while the processor is running, no action is taken.

StopProcessing(CancellationToken)

Signals the EventProcessorClient to stop processing events. Should this method be called while the processor is not running, no action is taken.

StopProcessingAsync(CancellationToken)

Signals the EventProcessorClient to stop processing events. Should this method be called while the processor is not running, no action is taken.

Events

PartitionClosingAsync

Performs the tasks needed when processing for a partition is being stopped. This commonly occurs when the partition is claimed by another event processor instance or when the current event processor instance is shutting down.

It is not recommended that the state of the processor be managed directly from within this method; requesting to start or stop the processor may result in a deadlock scenario, especially if using the synchronous form of the call.

PartitionInitializingAsync

Performs the tasks to initialize a partition, and its associated context, for event processing.

It is not recommended that the state of the processor be managed directly from within this method; requesting to start or stop the processor may result in a deadlock scenario, especially if using the synchronous form of the call.

ProcessErrorAsync

Performs the tasks needed when an unexpected exception occurs within the operation of the event processor infrastructure. Implementation is mandatory.

This error handler is invoked when there is an exception observed within the EventProcessorClient itself; it is not invoked for exceptions in code that has been implemented to process events or other event handlers and extension points that execute developer code. The EventProcessorClient will make every effort to recover from exceptions and continue processing. Should an exception that cannot be recovered from be encountered, the processor will attempt to forfeit ownership of all partitions that it was processing so that work may be redistributed.

The exceptions surfaced to this method may be fatal or non-fatal; because the processor may not be able to accurately predict whether an exception was fatal or whether its state was corrupted, this method has responsibility for making the determination as to whether processing should be terminated or restarted. The method may do so by calling Stop on the processor instance and then, if desired, calling Start on the processor.

It is recommended that, for production scenarios, the decision be made by considering observations made by this error handler, the method invoked when initializing processing for a partition, and the method invoked when processing for a partition is stopped. Many developers will also include data from their monitoring platforms in this decision as well.

As with event processing, should an exception occur in the code for the error handler, the event processor will allow it to bubble and will not attempt to handle it in any way. Developers are strongly encouraged to take exception scenarios into account and guard against them using try/catch blocks and other means as appropriate.

ProcessEventAsync

Performs the tasks needed to process a batch of events for a given partition as they are read from the Event Hubs service. Implementation is mandatory.

Should an exception occur within the code for this handler, the EventProcessorClient will allow it to bubble and will not surface to the error handler or attempt to handle it in any way. Developers are strongly encouraged to take exception scenarios into account, including the need to retry processing, and guard against them using try/catch blocks and other means, as appropriate.

It is not recommended that the state of the processor be managed directly from within this handler; requesting to start or stop the processor may result in a deadlock scenario, especially if using the synchronous form of the call.

Applies to