/// <summary> /// Checks if there are any registered exceptions to the current message and /// if all of them are <see cref="FailFastException"/>, then mark the message /// as failed too many times. /// </summary> public async Task Process(IncomingStepContext context, Func <Task> next) { try { await next(); var deadletterCommand = context.Load <ManualDeadletterCommand>(); if (deadletterCommand != null) { await ProcessDeadletterCommand(context, deadletterCommand); } } catch (Exception exception) { var transportMessage = context.Load <TransportMessage>(); var messageId = transportMessage.GetMessageId(); if (_failFastChecker.ShouldFailFast(messageId, exception)) { // if we're currently executing a 2nd level retry, it's the 2nd level surrogate message ID we must mark as final var messageIdToMarkAsFinal = context.Load <bool>(SimpleRetryStrategyStep.DispatchAsFailedMessageKey) ? SimpleRetryStrategyStep.GetSecondLevelMessageId(messageId) : messageId; _errorTracker.MarkAsFinal(messageIdToMarkAsFinal); } throw; } }
public bool ShouldFailFast(string messageId, Exception exception) { switch (exception) { // fail fast on our domain exception case DomainException _: return(true); // delegate all other behavior to default default: return(_failFastChecker.ShouldFailFast(messageId, exception)); } }
/// <summary> /// Checks if there are any registered exceptions to the current message and /// if all of them are <see cref="FailFastException"/>, then mark the message /// as failed too many times. /// </summary> public async Task Process(IncomingStepContext context, Func <Task> next) { try { await next(); } catch (Exception exception) { var transportMessage = context.Load <TransportMessage>(); var messageId = transportMessage.GetMessageId(); if (_failFastChecker.ShouldFailFast(messageId, exception)) { _errorTracker.MarkAsFinal(messageId); } throw; } }
/// <summary> /// Checks if there are any registered exceptions to the current message and /// if all of them are <see cref="FailFastException"/>, then mark the message /// as failed too many times. /// </summary> public async Task Process(IncomingStepContext context, Func <Task> next) { try { await next().ConfigureAwait(false); } catch (Exception exception) { var transportMessage = context.Load <TransportMessage>(); var messageId = transportMessage.GetMessageId(); if (_failFastChecker.ShouldFailFast(messageId, exception)) { _errorTracker.RegisterError(messageId, exception, final: true); } throw; } }
private void _checkFinal(string messageId, int?transportDeliveryCount, bool beforeTry) { var exceptions = _errorTracker.GetExceptions(messageId); // +1 as DeliveryCount is 1-based and is charged prior to 'receive' var deliveryCountFromExceptions = exceptions.Count() + 1; // if transport doesn't has deliveryCount, use the count of the Exceptions. var deliveryCount = (transportDeliveryCount ?? 0) > deliveryCountFromExceptions ? transportDeliveryCount : deliveryCountFromExceptions; if (beforeTry == true) { deliveryCount--; } if ((deliveryCount >= _arkRetryStrategySettings.MaxDeliveryAttempts && exceptions.Any()) || exceptions.Any(x => _failFastChecker.ShouldFailFast(messageId, x))) { _errorTracker.MarkAsFinal(messageId); } }
/// <summary> /// Checks if there are any registered exceptions to the current message and /// if all of them are <see cref="FailFastException"/>, then mark the message /// as failed too many times. /// </summary> public async Task Process(IncomingStepContext context, Func <Task> next) { try { await next(); var deadletterCommand = context.Load <ManualDeadletterCommand>(); if (deadletterCommand != null) { await ProcessDeadletterCommand(context, deadletterCommand); } } catch (Exception exception) { var transportMessage = context.Load <TransportMessage>(); var messageId = transportMessage.GetMessageId(); if (_failFastChecker.ShouldFailFast(messageId, exception)) { _errorTracker.MarkAsFinal(messageId); } throw; } }
public bool ShouldFailFast(string messageId, Exception exception) { return(exception is TException specificException && _predicate(specificException) || _failFastChecker.ShouldFailFast(messageId, exception)); }