示例#1
0
        /// <summary>
        /// Includes an outbox in the consume filter path, which delays outgoing messages until the return path
        /// of the pipeline returns to the outbox filter. At this point, the message execution pipeline should be
        /// nearly complete with only the ack remaining. If an exception is thrown, the messages are not sent/published.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="configure">Configure the outbox</param>
        public static void UseInMemoryOutbox <TMessage>(this IHandlerConfigurator <TMessage> configurator, Action <IOutboxConfigurator> configure = default)
            where TMessage : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var observer = new InMemoryOutboxHandlerConfigurationObserver(configure);

            configurator.ConnectHandlerConfigurationObserver(observer);
        }
        /// <summary>
        /// Configures the message retry for the handler, regardless of message type.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="configure"></param>
        public static void UseScheduledRedelivery <TMessage>(this IHandlerConfigurator <TMessage> configurator, Action <IRetryConfigurator> configure)
            where TMessage : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var observer = new MessageRedeliveryHandlerConfigurationObserver(configure);

            configurator.ConnectHandlerConfigurationObserver(observer);
        }
        /// <summary>
        /// Limits the number of concurrent messages consumed by the handler.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="concurrentMessageLimit">The concurrent message limit for the handler message type</param>
        public static void UseConcurrentMessageLimit <TMessage>(this IHandlerConfigurator <TMessage> configurator, int concurrentMessageLimit)
            where TMessage : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var observer = new ConcurrencyLimitHandlerConfigurationObserver(concurrentMessageLimit);

            configurator.ConnectHandlerConfigurationObserver(observer);
        }
        /// <summary>
        /// Configures the message retry for the consumer consumer, regardless of message type.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="busFactoryConfigurator">
        /// The bus factory configurator, to connect the observer, to cancel retries if the bus is stopped
        /// </param>
        /// <param name="configure"></param>
        public static void UseMessageRetry <TMessage>(this IHandlerConfigurator <TMessage> configurator, IBusFactoryConfigurator busFactoryConfigurator,
                                                      Action <IRetryConfigurator> configure)
            where TMessage : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var retryObserver = new RetryBusObserver();

            busFactoryConfigurator.ConnectBusObserver(retryObserver);

            var observer = new MessageRetryHandlerConfigurationObserver(retryObserver.Stopping, configure);

            configurator.ConnectHandlerConfigurationObserver(observer);
        }
        /// <summary>
        /// Limits the number of concurrent messages consumed by the handler.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="concurrentMessageLimit">The concurrent message limit for the handler message type</param>
        /// <param name="managementEndpointConfigurator">A management endpoint configurator to support runtime adjustment</param>
        /// <param name="id">An identifier for the concurrency limit to allow selective adjustment</param>
        public static void UseConcurrentMessageLimit <TMessage>(this IHandlerConfigurator <TMessage> configurator, int concurrentMessageLimit,
                                                                IManagementEndpointConfigurator managementEndpointConfigurator, string id = null)
            where TMessage : class
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            var observer = new ConcurrencyLimitHandlerConfigurationObserver(concurrentMessageLimit, id);

            configurator.ConnectHandlerConfigurationObserver(observer);

            managementEndpointConfigurator.Instance(observer.Limiter, x =>
            {
                x.UseConcurrentMessageLimit(1);
                x.Message <SetConcurrencyLimit>(m => m.UseRetry(r => r.None()));
            });
        }