Share via


EventProcessor<TPartition> Class

Definition

Provides a base for creating a custom processor which consumes events across all partitions of a given Event Hub for 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 abstract class EventProcessor<TPartition> where TPartition : EventProcessorPartition, new()
type EventProcessor<'Partition (requires 'Partition :> EventProcessorPartition and 'Partition : (new : unit -> 'Partition))> = class
Public MustInherit Class EventProcessor(Of TPartition)

Type Parameters

TPartition

The context of the partition for which an operation is being performed.

Inheritance
EventProcessor<TPartition>
Derived

Remarks

To enable coordination for sharing of partitions between EventProcessor<TPartition> instances, they will assert exclusive read access to partitions for the consumer group. No other readers should be active in the consumer group other than processors intending to collaborate. Non-exclusive readers will be denied access; exclusive readers, including processors using a different storage locations, will interfere with the processor's operation and performance.

The EventProcessor<TPartition> is safe to cache and use for the lifetime of an application, which is the recommended approach. The processor is responsible for ensuring efficient network, CPU, and memory use. Calling either StopProcessingAsync(CancellationToken) or StopProcessing(CancellationToken) when all processing is complete or as the application is shutting down will ensure that network resources and other unmanaged objects are properly cleaned up.

Constructors

EventProcessor<TPartition>()

Initializes a new instance of the EventProcessor<TPartition> class.

EventProcessor<TPartition>(Int32, String, String, EventProcessorOptions)

Initializes a new instance of the EventProcessor<TPartition> class.

EventProcessor<TPartition>(Int32, String, String, String, AzureNamedKeyCredential, EventProcessorOptions)

Initializes a new instance of the EventProcessor<TPartition> class.

EventProcessor<TPartition>(Int32, String, String, String, AzureSasCredential, EventProcessorOptions)

Initializes a new instance of the EventProcessor<TPartition> class.

EventProcessor<TPartition>(Int32, String, String, String, EventProcessorOptions)

Initializes a new instance of the EventProcessor<TPartition> class.

EventProcessor<TPartition>(Int32, String, String, String, TokenCredential, EventProcessorOptions)

Initializes a new instance of the EventProcessor<TPartition> 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.

EnableBatchTracing

Indicates whether or not this event processor should instrument batch event processing calls with distributed tracing. Implementations that instrument event processing themselves should set this to false.

EventHubName

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

EventHubProperties

The properties associated with the Event Hub being read from. This value is updated in each load balancing cycle.

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.

Methods

ClaimOwnershipAsync(IEnumerable<EventProcessorPartitionOwnership>, CancellationToken)

Attempts to claim ownership of the specified partitions for processing. This operation is used by load balancing to enable distributing the responsibility for processing partitions for an Event Hub and consumer group pairing amongst the active event processors.

CreateConnection()

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

GetCheckpointAsync(String, CancellationToken)

Returns a checkpoint for the Event Hub, consumer group, and identifier of the partition associated with the event processor instance, so that processing for a given partition can be properly initialized. The default implementation calls the Azure.Messaging.EventHubs.Primitives.EventProcessor`1.ListCheckpointsAsync(System.Threading.CancellationToken) and filters results by PartitionId. It's recommended that this method is overridden in EventProcessor<TPartition> implementations to achieve an optimal performance.

ListOwnershipAsync(CancellationToken)

Requests 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 during load balancing to allow the processor to discover other active collaborators and to make decisions about how to best balance work between them.

ListPartitionIdsAsync(EventHubConnection, CancellationToken)

Queries for the identifiers of the Event Hub partitions.

OnInitializingPartitionAsync(TPartition, CancellationToken)

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

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.

OnProcessingErrorAsync(Exception, TPartition, String, CancellationToken)

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

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.

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.

StartProcessing(CancellationToken)

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

StartProcessingAsync(CancellationToken)

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

StopProcessing(CancellationToken)

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

StopProcessingAsync(CancellationToken)

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

UpdateCheckpointAsync(String, CheckpointPosition, CancellationToken)

Creates or updates a checkpoint for a specific partition, identifying a position in the partition's event stream that an event processor should begin reading from.

UpdateCheckpointAsync(String, Int64, Nullable<Int64>, CancellationToken)

Creates or updates a checkpoint for a specific partition, identifying a position in the partition's event stream that an event processor should begin reading from.

ValidateProcessingPreconditions(CancellationToken)

Performs the tasks needed to validate basic configuration and permissions of the dependencies needed for the processor to function.

Applies to