private static RecoverabilityAction CustomerExceptionPolicy(RecoverabilityConfig config, ErrorContext context) { var unrecover = context.Exception is UnrecoverableException; var customer = context.Exception is CustomerException; var immediateIdx = context.ImmediateProcessingFailures; var immediateMax = config.Immediate.MaxNumberOfRetries; var delayIdx = context.DelayedDeliveriesPerformed; var delayMax = config.Delayed.MaxNumberOfRetries; if (!unrecover && immediateIdx < immediateMax) { Console.WriteLine($"DelayedRetry {delayIdx}, ImmediateRetry {immediateIdx}"); return(RecoverabilityAction.ImmediateRetry()); } if (!unrecover && immediateIdx == immediateMax && delayIdx < delayMax) { Console.WriteLine($"DelayedRetry {delayIdx}"); return(RecoverabilityAction.DelayedRetry(config.Delayed.TimeIncrease)); } if (customer && delayIdx == delayMax) { Console.WriteLine("Alert customer exception"); } return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { // early decisions and return before custom policy is invoked // i.e. all unrecoverable exceptions should always go to customized error queue foreach (var exceptionType in config.Failed.UnrecoverableExceptionTypes) { if (exceptionType.IsInstanceOfType(context.Exception)) { return(RecoverabilityAction.MoveToError("customErrorQueue")); } } // If it does not make sense to have this message around anymore // it can be discarded with a reason. if (context.Exception is MyBusinessTimedOutException) { return(RecoverabilityAction.Discard("Business operation timed out.")); } // override delayed retry decision for custom exception // i.e. MyOtherBusinessException should do fixed backoff of 5 seconds if (context.Exception is MyOtherBusinessException && context.DelayedDeliveriesPerformed < config.Delayed.MaxNumberOfRetries) { return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); } // in all other cases No Immediate or Delayed Retries, go to default error queue return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
static RecoverabilityAction OrderPlacedPolicy(RecoverabilityConfig config, ErrorContext context) { var errorCategory = ErrorCategory.Unknown; if (context.Message.Headers.ContainsKey("NServiceBus.EnclosedMessageTypes")) { if (context.Message.Headers["NServiceBus.EnclosedMessageTypes"].StartsWith("Messages.Commands.PlaceOrder")) { errorCategory = FailPolicy.GetPolicy("Messages.Commands.PlaceOrder").GetCategory(context.Exception); } else if (context.Message.Headers["NServiceBus.EnclosedMessageTypes"].StartsWith("Messages.Commands.CancelOrder")) { errorCategory = FailPolicy.GetPolicy("Messages.Commands.CancelOrder").GetCategory(context.Exception); } } if (errorCategory == ErrorCategory.Persistent) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } else if (errorCategory == ErrorCategory.SemiTransient) { return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(60))); } // invocation of default recoverability policy return(DefaultRecoverabilityPolicy.Invoke(config, context)); }
static Func <ErrorContext, RecoverabilityAction> CreatePolicy(int maxImmediateRetries = 2, int maxDelayedRetries = 2, TimeSpan?delayedRetryDelay = null, HashSet <Type> unrecoverableExceptions = null) { var failedConfig = new FailedConfig("errorQueue", unrecoverableExceptions ?? new HashSet <Type>()); var config = new RecoverabilityConfig(new ImmediateConfig(maxImmediateRetries), new DelayedConfig(maxDelayedRetries, delayedRetryDelay.GetValueOrDefault(TimeSpan.FromSeconds(2))), failedConfig); return(context => CustomizedRecoverabilityPolicy.MyCustomRetryPolicy(config, context)); }
RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { if (context.Exception is MyBusinessException) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } return(DefaultRecoverabilityPolicy.Invoke(config, context)); }
RecoverabilityAction RetryPolicy(RecoverabilityConfig config, ErrorContext context) { if (context.DelayedDeliveriesPerformed == 0) { return(RecoverabilityAction.DelayedRetry(TimeSpan.FromMilliseconds(10))); } return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
static RecoverabilityAction RecoverabilityPolicy(RecoverabilityConfig config, ErrorContext errorContext) { if (errorContext.ImmediateProcessingFailures <= MaxNumberOfImmediateRetries) { return(RecoverabilityAction.ImmediateRetry()); } return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
private RecoverabilityAction CreateSubjectCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { // In this custom policy, we are electing to move the PoisonedMessages to a different error queue for resolution, so they will use a different error queue to the standard one (so can be monitored easily). // You could add whatever logic you liked here to put different messages in different queues. return(config.Failed.UnrecoverableExceptionTypes.Count(exType => exType.IsInstanceOfType(context.Exception)) > 0 ? RecoverabilityAction.MoveToError("customErrorQueue") : DefaultRecoverabilityPolicy.Invoke(config, context)); }
RecoverabilityAction OnAuditError(RecoverabilityConfig config, ErrorContext errorContext) { var recoverabilityAction = DefaultRecoverabilityPolicy.Invoke(config, errorContext); if (recoverabilityAction is MoveToError) { importFailuresHandler.Handle(errorContext).GetAwaiter().GetResult(); } return(recoverabilityAction); }
RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { var action = DefaultRecoverabilityPolicy.Invoke(config, context); if (!(action is DelayedRetry delayedRetryAction)) { return(action); } // Override default delivery delay. return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); }
public static RecoverabilityAction UserServiceRetryPolicyInvoke(RecoverabilityConfig config, ErrorContext context) { var action = DefaultRecoverabilityPolicy.Invoke(config, context); if (!(action is DelayedRetry)) { return(action); } if (context.Exception is NullReferenceException) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } return(RecoverabilityAction.DelayedRetry(TimeSpan.FromMinutes(3))); }
public void Setup() { context = new ErrorContext( new Exception(), new Dictionary <string, string>(), Guid.NewGuid().ToString(), new byte[0], new TransportTransaction(), 2); config = new RecoverabilityConfig( new ImmediateConfig(0), new DelayedConfig(4, TimeSpan.FromSeconds(10)), new FailedConfig("error", new HashSet <Type>())); }
RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { // invocation of default recoverability policy var action = DefaultRecoverabilityPolicy.Invoke(config, context); // override delayed retry decision for custom exception // i.e. MyOtherBusinessException should do fixed backoff of 5 seconds if (action is DelayedRetry delayedRetryAction && context.Exception is MyOtherBusinessException) { return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); } return(action); }
RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { var action = DefaultRecoverabilityPolicy.Invoke(config, context); if (!(action is DelayedRetry delayedRetryAction)) { return(action); } if (context.Exception is MyBusinessException) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } // Override default delivery delay. return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); }
static RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { var numberOfRetries = context.DelayedDeliveriesPerformed; var exceptionInstance = context.Exception; // call the default recoverability of default behavior is desired var action = DefaultRecoverabilityPolicy.Invoke(config, context); if (action is DelayedRetry delayedRetryAction) { // perform some logic and decide when to do delayed retries return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); } return(action); }
public RecoverabilityAction Invoke(RecoverabilityConfig config, ErrorContext errorContext) { var action = DefaultRecoverabilityPolicy.Invoke(config, errorContext); if (action is MoveToError) { if (SendFailedMessagesToErrorQueue) { return(action); } // 7.2 offers a Discard option, but we want to bubble up the exception so it can fail the function invocation. throw new Exception("Failed to process message.", errorContext.Exception); } return(action); }
public RecoverabilityAction WebhookRetryPolicy(RecoverabilityConfig config, ErrorContext context) { if (context.Exception is WebhookExceptionRetryPerPolicy) { // Check that the number of delayed deliveries does not exceed configurable webhook retry count if (context.DelayedDeliveriesPerformed < ConfigHelper.WebhookRetryCount) { // Set delayed retry internal to that set by the configurable webhook retry internal return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(ConfigHelper.WebhookRetryInterval))); } // If the webhook could not be delivered within the specified number of retry attempts. Log error and send to ErrorQueue string errorMsg = $"Failed to send webhook after {context.DelayedDeliveriesPerformed} attempts."; Log.Error(errorMsg); return(RecoverabilityAction.MoveToError(errorMsg)); } // For all other exceptions, fall back to default policy return(DefaultRecoverabilityPolicy.Invoke(config, context)); }
RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { // early decisions and return before custom policy is invoked // i.e. MyBusinessException should always go to customized error queue if (context.Exception is MyBusinessException) { return(RecoverabilityAction.MoveToError("customErrorQueue")); } // override delayed retry decision for custom exception // i.e. MyOtherBusinessException should do fixed backoff of 5 seconds if (context.Exception is MyOtherBusinessException && context.DelayedDeliveriesPerformed <= config.Delayed.MaxNumberOfRetries) { return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); } // in all other cases No Immediate or Delayed Retries, go to default error queue return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
public RecoverabilityAction Retry(RecoverabilityConfig recoverabilityConfig, ErrorContext errorContext) { if (errorContext.Exception is OptimisticConcurrencyException) { var ttl = errorContext.Message.Headers[ ApplicationConfiguration.Instance.GetValue <string>( "ProductService:RetryPolicy:HeaderNames:UpdateStockInProduct")]; if (Convert.ToInt32(ttl) == 0) { return(RecoverabilityAction.MoveToError(recoverabilityConfig.Failed.ErrorQueue)); } //TODO:Kudret--> Beklediğim bir senaryo, bu yüzden immediate olarak retry etsin return(RecoverabilityAction.ImmediateRetry()); } return(DefaultRecoverabilityPolicy.Invoke(recoverabilityConfig, errorContext)); }
public static RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { var action = DefaultRecoverabilityPolicy.Invoke(config, context); // If not a retry then continue if (!(action is DelayedRetry delayedRetryAction)) { return(action); } // Check for concrete exception or business custom exception if (context.Exception is InvalidCastException) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } // Override default delivery delay. return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); }
public static RecoverabilityAction MyCoronaServiceRetryPolicy(RecoverabilityConfig config, ErrorContext context) { var action = DefaultRecoverabilityPolicy.Invoke(config, context); if (!(action is DelayedRetry delayedRetryAction)) { return(action); } /* if (context.Exception is PatientNotExistExcption) * { * return RecoverabilityAction.MoveToError(config.Failed.ErrorQueue); * }*/ if (context.Exception is NullReferenceException) { return(RecoverabilityAction.Discard("Business operation timed out.")); } // Override default delivery delay. return(RecoverabilityAction.DelayedRetry(TimeSpan.FromMinutes(3))); }
RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { // early decisions and return before custom policy is invoked // i.e. MyBusinessException should always go to error if (context.Exception is MyBusinessException) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } // invocation of default recoverability policy var action = DefaultRecoverabilityPolicy.Invoke(config, context); // override delayed retry decision for custom exception // i.e. MyOtherBusinessException should do fixed backoff of 5 seconds if (action is DelayedRetry delayedRetryAction && context.Exception is MyOtherBusinessException) { return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5))); } return(action); }
public static RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context) { // early decisions and return before custom policy is invoked // i.e. all unrecoverable exceptions should always go to customized error queue foreach (var exceptionType in config.Failed.UnrecoverableExceptionTypes) { if (exceptionType.IsInstanceOfType(context.Exception)) { return(RecoverabilityAction.MoveToError("customErrorQueue")); } } // If it does not make sense to have this message around anymore // it can be discarded with a reason. if (context.Exception is MyBusinessTimedOutException) { return(RecoverabilityAction.Discard("Business operation timed out.")); } // in all other cases No Immediate or Delayed Retries, go to default error queue return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); }
private static RecoverabilityAction SubscriberServiceRetryPolicy(RecoverabilityConfig config, ErrorContext context) { var action = DefaultRecoverabilityPolicy.Invoke(config, context); if (!(action is DelayedRetry delayedRetryAction)) { return(action); } if (context.Exception is UserNotFoundException) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } // Override default delivery delay. /* var recoverability = endpointConfiguration.Recoverability(); * recoverability.Delayed( * customizations: delayed => * { * delayed.NumberOfRetries(3); * delayed.TimeIncrease(TimeSpan.FromMinutes(3)); * });*/ return(RecoverabilityAction.DelayedRetry(TimeSpan.FromMinutes(3))); }
public RecoverabilityAction Invoke(RecoverabilityConfig config, ErrorContext errorContext) { return actions.Dequeue(); }
static Func<ErrorContext, RecoverabilityAction> CreatePolicy(int maxImmediateRetries = 2, int maxDelayedRetries = 2, TimeSpan? delayedRetryDelay = null) { var config = new RecoverabilityConfig(new ImmediateConfig(maxImmediateRetries), new DelayedConfig(maxDelayedRetries, delayedRetryDelay.GetValueOrDefault(TimeSpan.FromSeconds(2))), new FailedConfig("errorQueue")); return context => DefaultRecoverabilityPolicy.Invoke(config, context); }
static Func <ErrorContext, RecoverabilityAction> CreatePolicy(int maxImmediateRetries = 2, int maxDelayedRetries = 2, TimeSpan?delayedRetryDelay = null) { var config = new RecoverabilityConfig(new ImmediateConfig(maxImmediateRetries), new DelayedConfig(maxDelayedRetries, delayedRetryDelay.GetValueOrDefault(TimeSpan.FromSeconds(2))), new FailedConfig("errorQueue")); return(context => DefaultRecoverabilityPolicy.Invoke(config, context)); }
static RecoverabilityAction RecoverabilityPolicy(RecoverabilityConfig config, ErrorContext errorContext) { if (errorContext.ImmediateProcessingFailures <= MaxNumberOfImmediateRetries) { return RecoverabilityAction.ImmediateRetry(); } return RecoverabilityAction.MoveToError(config.Failed.ErrorQueue); }
public static RecoverabilityAction Invoke(ErrorContext errorContext, Func <IncomingMessage, Exception, int, TimeSpan> retryPolicy, RecoverabilityConfig config) { var currentRetry = errorContext.DelayedDeliveriesPerformed + 1; var timeIncrease = retryPolicy(errorContext.Message, errorContext.Exception, currentRetry); if (timeIncrease <= TimeSpan.MinValue) { return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue)); } return(RecoverabilityAction.DelayedRetry(timeIncrease)); }
static RecoverabilityAction OnError(RecoverabilityConfig arg1, ErrorContext arg2) { return(RecoverabilityAction.ImmediateRetry()); }
public RecoverabilityAction Invoke(RecoverabilityConfig config, ErrorContext errorContext) { return(actions.Dequeue()); }