Table of Contents

Class ErrorPolicyImplementation

Namespace
Silverback.Messaging.Consuming.ErrorHandling
Assembly
Silverback.Integration.dll

An error policy is used to handle errors that may occur while processing the inbound messages.

public abstract class ErrorPolicyImplementation : IErrorPolicyImplementation
Inheritance
ErrorPolicyImplementation
Implements
Inherited Members

Constructors

ErrorPolicyImplementation(int?, IReadOnlyCollection<Type>, IReadOnlyCollection<Type>, Func<IRawInboundEnvelope, Exception, bool>?, Func<IRawInboundEnvelope, Exception, object?>?, IServiceProvider, ISilverbackLogger<ErrorPolicyBase>)

Initializes a new instance of the ErrorPolicyImplementation class.

protected ErrorPolicyImplementation(int? maxFailedAttempts, IReadOnlyCollection<Type> excludedExceptions, IReadOnlyCollection<Type> includedExceptions, Func<IRawInboundEnvelope, Exception, bool>? applyRule, Func<IRawInboundEnvelope, Exception, object?>? messageToPublishFactory, IServiceProvider serviceProvider, ISilverbackLogger<ErrorPolicyBase> logger)

Parameters

maxFailedAttempts int?

The number of times this policy should be applied to the same message in case of multiple failed attempts.

excludedExceptions IReadOnlyCollection<Type>

The collection of exception types this policy doesn't have to be applied to.

includedExceptions IReadOnlyCollection<Type>

The collection of exception types this policy have to be applied to.

applyRule Func<IRawInboundEnvelope, Exception, bool>

The custom apply rule function.

messageToPublishFactory Func<IRawInboundEnvelope, Exception, object>

The factory that builds the message to be published after the policy is applied.

serviceProvider IServiceProvider

The IServiceProvider.

logger ISilverbackLogger<ErrorPolicyBase>

The ISilverbackLogger<TCategoryName>.

Methods

ApplyPolicyAsync(ConsumerPipelineContext, Exception)

Executes the current policy.

protected abstract Task<bool> ApplyPolicyAsync(ConsumerPipelineContext context, Exception exception)

Parameters

context ConsumerPipelineContext

The ConsumerPipelineContext related to the message that failed to be processed.

exception Exception

The exception that was thrown during the processing.

Returns

Task<bool>

A Task<TResult> representing the asynchronous operation. The task result contains the action that the consumer should perform (e.g. skip the message or stop consuming).

CanHandle(ConsumerPipelineContext, Exception)

Returns a boolean value indicating whether the policy can handle the specified envelopes and the specified exception.

public virtual bool CanHandle(ConsumerPipelineContext context, Exception exception)

Parameters

context ConsumerPipelineContext

The ConsumerPipelineContext related to the message that failed to be processed.

exception Exception

The exception that was thrown during the processing.

Returns

bool

A value indicating whether the specified envelopes and exception can be handled.

HandleErrorAsync(ConsumerPipelineContext, Exception)

Performs the necessary actions to handle the error (including invoking the IConsumerTransactionManager).

public Task<bool> HandleErrorAsync(ConsumerPipelineContext context, Exception exception)

Parameters

context ConsumerPipelineContext

The ConsumerPipelineContext related to the message that failed to be processed.

exception Exception

The exception that was thrown during the processing.

Returns

Task<bool>

A Task<TResult> representing the asynchronous operation. The task result contains a boolean flag indicating whether the error was handled. If false is returned the exception will be rethrown and the consumer will stop.