Udostępnij za pośrednictwem


EventProcessor<TPartition>.OnProcessingErrorAsync Method

Definition

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

protected abstract System.Threading.Tasks.Task OnProcessingErrorAsync (Exception exception, TPartition partition, string operationDescription, System.Threading.CancellationToken cancellationToken);
abstract member OnProcessingErrorAsync : Exception * 'Partition * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Protected MustOverride Function OnProcessingErrorAsync (exception As Exception, partition As TPartition, operationDescription As String, cancellationToken As CancellationToken) As Task

Parameters

exception
Exception

The exception that occurred during operation of the event processor.

partition
TPartition

The context of the partition associated with the error, if any; otherwise, null. This may only be initialized for members of EventProcessorPartition, depending on the point at which the error occurred.

operationDescription
String

A short textual description of the operation during which the exception occurred; intended to be informational only.

cancellationToken
CancellationToken

A CancellationToken instance to signal the request to cancel the processing. This is most likely to occur when the processor is shutting down.

Returns

Remarks

This error handler is invoked when there is an exception observed within the event processor itself; it is not invoked for exceptions in code that has been implemented to process events or other overrides and extension points that are not critical to the processor's operation. The event processor 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. If desired, this can be done safely by calling StopProcessingAsync(CancellationToken) and/or StartProcessingAsync(CancellationToken).

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.

This method will be invoked concurrently and is not awaited by the processor, as each error is independent. No time limit is imposed on an invocation; it is safe for implementations to perform long-running operations and retries as needed.

Applies to