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
maxFailedAttemptsint?The number of times this policy should be applied to the same message in case of multiple failed attempts.
excludedExceptionsIReadOnlyCollection<Type>The collection of exception types this policy doesn't have to be applied to.
includedExceptionsIReadOnlyCollection<Type>The collection of exception types this policy have to be applied to.
applyRuleFunc<IRawInboundEnvelope, Exception, bool>The custom apply rule function.
messageToPublishFactoryFunc<IRawInboundEnvelope, Exception, object>The factory that builds the message to be published after the policy is applied.
serviceProviderIServiceProviderThe IServiceProvider.
loggerISilverbackLogger<ErrorPolicyBase>
Methods
ApplyPolicyAsync(ConsumerPipelineContext, Exception)
Executes the current policy.
protected abstract Task<bool> ApplyPolicyAsync(ConsumerPipelineContext context, Exception exception)
Parameters
contextConsumerPipelineContextThe ConsumerPipelineContext related to the message that failed to be processed.
exceptionExceptionThe 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
contextConsumerPipelineContextThe ConsumerPipelineContext related to the message that failed to be processed.
exceptionExceptionThe 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
contextConsumerPipelineContextThe ConsumerPipelineContext related to the message that failed to be processed.
exceptionExceptionThe 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
falseis returned the exception will be rethrown and the consumer will stop.