Example #1
0
        /// <summary>
        /// Configures the simple retry strategy, using the specified error queue address and number of delivery attempts
        /// </summary>
        /// <param name="optionsConfigurer">(extension method target)</param>
        /// <param name="errorQueueAddress">Specifies the name of the error queue</param>
        /// <param name="maxDeliveryAttempts">Specifies how many delivery attempts should be made before forwarding a failed message to the error queue</param>
        /// <param name="secondLevelRetriesEnabled">Specifies whether second level retries should be enabled - when enabled, the message will be dispatched wrapped in an <see cref="IFailed{TMessage}"/> after the first <paramref name="maxDeliveryAttempts"/> delivery attempts, allowing a different handler to handle the message. Dispatch of the <see cref="IFailed{TMessage}"/> is subject to the same <paramref name="maxDeliveryAttempts"/> delivery attempts</param>
        /// <param name="errorDetailsHeaderMaxLength">Specifies a MAX length of the error details to be enclosed as the <see cref="Headers.ErrorDetails"/> header. As the enclosed error details can sometimes become very long (especially when using many delivery attempts), depending on the transport's capabilities it might sometimes be necessary to truncate the error details</param>
        public static void SimpleRetryStrategy(this OptionsConfigurer optionsConfigurer,
                                               string errorQueueAddress        = SimpleRetryStrategySettings.DefaultErrorQueueName,
                                               int maxDeliveryAttempts         = SimpleRetryStrategySettings.DefaultNumberOfDeliveryAttempts,
                                               bool secondLevelRetriesEnabled  = false,
                                               int errorDetailsHeaderMaxLength = int.MaxValue)
        {
            if (optionsConfigurer == null)
            {
                throw new ArgumentNullException(nameof(optionsConfigurer));
            }

            optionsConfigurer.Register(c => new SimpleRetryStrategySettings(errorQueueAddress, maxDeliveryAttempts, secondLevelRetriesEnabled, errorDetailsHeaderMaxLength));

            if (secondLevelRetriesEnabled)
            {
                optionsConfigurer.Decorate <IPipeline>(c =>
                {
                    var pipeline     = c.Get <IPipeline>();
                    var errorTracker = c.Get <IErrorTracker>();

                    var incomingStep = new FailedMessageWrapperStep(errorTracker);
                    var outgoingStep = new VerifyCannotSendFailedMessageWrapperStep();

                    return(new PipelineStepInjector(pipeline)
                           .OnReceive(incomingStep, PipelineRelativePosition.After, typeof(DeserializeIncomingMessageStep))
                           .OnSend(outgoingStep, PipelineRelativePosition.Before, typeof(SerializeOutgoingMessageStep)));
                });
            }
        }
Example #2
0
        /// <summary>
        /// Configures the simple retry strategy, using the specified error queue address and number of delivery attempts
        /// </summary>
        public static void SimpleRetryStrategy(this OptionsConfigurer optionsConfigurer,
                                               string errorQueueAddress       = SimpleRetryStrategySettings.DefaultErrorQueueName,
                                               int maxDeliveryAttempts        = SimpleRetryStrategySettings.DefaultNumberOfDeliveryAttempts,
                                               bool secondLevelRetriesEnabled = false)
        {
            optionsConfigurer.Register(c => new SimpleRetryStrategySettings(errorQueueAddress, maxDeliveryAttempts, secondLevelRetriesEnabled));

            if (secondLevelRetriesEnabled)
            {
                optionsConfigurer.Decorate <IPipeline>(c =>
                {
                    var pipeline     = c.Get <IPipeline>();
                    var errorTracker = c.Get <IErrorTracker>();
                    var step         = new FailedMessageWrapperStep(errorTracker);

                    return(new PipelineStepInjector(pipeline)
                           .OnReceive(step, PipelineRelativePosition.After, typeof(DeserializeIncomingMessageStep)));
                });
            }
        }