예제 #1
0
        RecoverabilityAction MyCustomRetryPolicy(RecoverabilityConfig config, ErrorContext context)
        {
            var action             = DefaultRecoverabilityPolicy.Invoke(config, context);
            var delayedRetryAction = action as DelayedRetry;

            if (delayedRetryAction == null)
            {
                return(action);
            }
            // Override default delivery delay.
            return(RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(5)));
        }
예제 #2
0
        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)));
        }
        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)));
        }
        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);
        }
        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 void DelayedRetry(FeatureConfigurationContext context)
        {
            #region SatelliteRecoverability-DelayedRetry

            context.AddSatelliteReceiver(
                name: "CustomSatellite",
                transportAddress: "targetQueue",
                runtimeSettings: PushRuntimeSettings.Default,
                recoverabilityPolicy: (config, errorContext) =>
            {
                return(RecoverabilityAction.DelayedRetry(
                           timeSpan: TimeSpan.FromMinutes(2)));
            },
                onMessage: OnMessage);

            #endregion
        }
예제 #7
0
 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));
 }
예제 #8
0
        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)));
        }
        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 Endpoint()
            {
                EndpointSetup <DefaultServer>((config, context) =>
                {
                    var testContext = (Context)context.ScenarioContext;

                    config.Recoverability()
                    .CustomPolicy((cfg, errorContext) =>
                    {
                        testContext.ErrorContexts.Add(errorContext);

                        if (errorContext.DelayedDeliveriesPerformed >= 1)
                        {
                            return(RecoverabilityAction.MoveToError(cfg.Failed.ErrorQueue));
                        }

                        return(RecoverabilityAction.DelayedRetry(TimeSpan.FromMilliseconds(1)));
                    });
                });
            }
예제 #11
0
        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)));
        }
        public async Task When_notification_turned_off_no_notification_should_be_raised()
        {
            var policy = RetryPolicy.Return(
                actions: new RecoverabilityAction[]
            {
                RecoverabilityAction.ImmediateRetry(),
                RecoverabilityAction.DelayedRetry(TimeSpan.FromSeconds(10)),
                RecoverabilityAction.MoveToError("errorQueue")
            });
            var executor     = CreateExecutor(policy, raiseNotifications: false);
            var errorContext = CreateErrorContext();

            await executor.Invoke(errorContext); //force retry

            await executor.Invoke(errorContext); //force delayed retry

            await executor.Invoke(errorContext); //force move to errors

            Assert.IsEmpty(messageRetriedNotifications);
            Assert.IsEmpty(messageFaultedNotifications);
        }
        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);
        }
예제 #14
0
        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)));
        }
예제 #15
0
        protected override void Setup(FeatureConfigurationContext context)
        {
            var settings          = context.Settings;
            var attachmentCleaner = settings.GetAttachmentCleaner();
            var attachmentFinder  = settings.GetAttachmentFinder();
            var smtpBuilder       = settings.GetSmtpBuilder();

            if (smtpBuilder == null)
            {
                smtpBuilder = () => new SmtpClient
                {
                    EnableSsl = true
                };
            }
            var serializer = GetDefaultSerializer(settings);
            var satellite  = new MailSatellite(attachmentFinder, attachmentCleaner, smtpBuilder, serializer);
            var tenSeconds = TimeSpan.FromSeconds(10);

            context.AddSatelliteReceiver(
                name: "MailSatelite",
                transportAddress: "Mail",
                runtimeSettings: PushRuntimeSettings.Default,
                recoverabilityPolicy: (config, errorContext) =>
            {
                if (errorContext.ImmediateProcessingFailures < 2)
                {
                    return(RecoverabilityAction.ImmediateRetry());
                }
                if (errorContext.DelayedDeliveriesPerformed < 3)
                {
                    return(RecoverabilityAction.DelayedRetry(tenSeconds));
                }
                return(RecoverabilityAction.MoveToError(config.Failed.ErrorQueue));
            },
                onMessage: satellite.OnMessageReceived);
        }
예제 #16
0
        static async Task Main()
        {
            const string endpointName = "HealthMinistry";

            Console.Title = endpointName;

            var endpointConfiguration = new EndpointConfiguration(endpointName);

            endpointConfiguration.EnableInstallers();

            endpointConfiguration.AuditProcessedMessagesTo("audit");

            endpointConfiguration.AuditSagaStateChanges(
                serviceControlQueue: "Particular.Servicecontrol");

            var settings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
            var serialization = endpointConfiguration.UseSerialization <NewtonsoftSerializer>();

            serialization.Settings(settings);


            var persistence = endpointConfiguration.UsePersistence <SqlPersistence>();


            var persistenceConnection = ConfigurationManager.ConnectionStrings["persistenceConnection"].ToString();

            var transportConnection = ConfigurationManager.ConnectionStrings["transportConnection"].ToString();

            persistence.SqlDialect <SqlDialect.MsSqlServer>();

            persistence.ConnectionBuilder(
                connectionBuilder: () =>
            {
                return(new SqlConnection(persistenceConnection));
            });


            var outboxSettings = endpointConfiguration.EnableOutbox();

            outboxSettings.KeepDeduplicationDataFor(TimeSpan.FromDays(6));
            outboxSettings.RunDeduplicationDataCleanupEvery(TimeSpan.FromMinutes(15));

            var recoverability = endpointConfiguration.Recoverability();

            recoverability.CustomPolicy(MyCoronaServiceRetryPolicy);

            var transport = endpointConfiguration.UseTransport <RabbitMQTransport>();

            transport.UseConventionalRoutingTopology()
            .ConnectionString(transportConnection);


            var routing = transport.Routing();

            routing.RouteToEndpoint(
                typeof(ISendEmail).Assembly, "HealthMinistry");



            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));
                }
                // Override default delivery delay.
                return(RecoverabilityAction.DelayedRetry(TimeSpan.FromMinutes(3)));
            }

            var conventions = endpointConfiguration.Conventions();

            conventions.DefiningCommandsAs(type => type.Namespace == "Messages.Commands");
            conventions.DefiningEventsAs(type => type.Namespace == "Messages.Events");

            var endpointInstance = await Endpoint.Start(endpointConfiguration)
                                   .ConfigureAwait(false);

            Console.WriteLine("Press Enter to exit.");
            Console.ReadLine();

            await endpointInstance.Stop()
            .ConfigureAwait(false);
        }