/// <summary> /// Invokes the default recovery policy. /// </summary> /// <param name="config">The recoverability configuration.</param> /// <param name="errorContext">The error context.</param> /// <returns>The recoverability action.</returns> public static RecoverabilityAction Invoke(RecoverabilityConfig config, ErrorContext errorContext) { Guard.AgainstNull(nameof(errorContext), errorContext); Guard.AgainstNull(nameof(config), config); // ReSharper disable once LoopCanBeConvertedToQuery foreach (var unrecoverableExceptionType in config.Failed.UnrecoverableExceptionTypes) { if (unrecoverableExceptionType.IsInstanceOfType(errorContext.Exception)) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } } if (errorContext.ImmediateProcessingFailures <= config.Immediate.MaxNumberOfRetries) { return(RecoverabilityAction.ImmediateRetry()); } TimeSpan delay; if (TryGetDelay(errorContext.Message, errorContext.DelayedDeliveriesPerformed, config.Delayed, out delay)) { return(RecoverabilityAction.DelayedRetry(delay)); } return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
public void UseNServiceBusPoisonMessageHandling(string errorQueue) { endpointConfiguration.Recoverability().CustomPolicy((c, e) => { return(RecoverabilityAction.MoveToError(errorQueue)); }); moveFailedMessagesToError = true; }
/// <summary> /// Invokes the default recovery policy. /// </summary> /// <param name="config">The recoverability configuration.</param> /// <param name="errorContext">The error context.</param> /// <returns>The recoverability action.</returns> public static RecoverabilityAction Invoke(RecoverabilityConfig config, ErrorContext errorContext) { if (errorContext.Exception is MessageDeserializationException) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } if (errorContext.ImmediateProcessingFailures <= config.Immediate.MaxNumberOfRetries) { return(RecoverabilityAction.ImmediateRetry()); } TimeSpan delay; if (TryGetDelay(errorContext.Message, errorContext.DelayedDeliveriesPerformed, config.Delayed, out delay)) { return(RecoverabilityAction.DelayedRetry(delay)); } return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
void SetupLegacyRetriesSatellite(FeatureConfigurationContext context) { var retriesQueueLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("Retries"); var retriesQueueTransportAddress = context.Settings.GetTransportAddress(retriesQueueLogicalAddress); var mainQueueLogicalAddress = context.Settings.LogicalAddress(); var mainQueueTransportAddress = context.Settings.GetTransportAddress(mainQueueLogicalAddress); var requiredTransactionMode = context.Settings.GetRequiredTransactionModeForReceives(); context.AddSatelliteReceiver("Legacy Retries Processor", retriesQueueTransportAddress, requiredTransactionMode, new PushRuntimeSettings(maxConcurrency: 1), (config, errorContext) => { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }, (builder, messageContext) => { var messageDispatcher = builder.Build <IDispatchMessages>(); var outgoingHeaders = messageContext.Headers; outgoingHeaders.Remove("NServiceBus.ExceptionInfo.Reason"); outgoingHeaders.Remove("NServiceBus.ExceptionInfo.ExceptionType"); outgoingHeaders.Remove("NServiceBus.ExceptionInfo.InnerExceptionType"); outgoingHeaders.Remove("NServiceBus.ExceptionInfo.HelpLink"); outgoingHeaders.Remove("NServiceBus.ExceptionInfo.Message"); outgoingHeaders.Remove("NServiceBus.ExceptionInfo.Source"); outgoingHeaders.Remove("NServiceBus.FailedQ"); outgoingHeaders.Remove("NServiceBus.TimeOfFailure"); //HINT: this header is added by v3 when doing SLR outgoingHeaders.Remove("NServiceBus.OriginalId"); var outgoingMessage = new OutgoingMessage(messageContext.MessageId, outgoingHeaders, messageContext.Body); var outgoingOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(mainQueueTransportAddress)); return(messageDispatcher.Dispatch(new TransportOperations(outgoingOperation), messageContext.TransportTransaction, messageContext.Extensions)); }); }