/// <summary> /// Limits the number of concurrent messages consumed by the consumer, regardless of message type. /// </summary> /// <param name="configurator"></param> /// <param name="concurrentMessageLimit">The concurrent message limit for all message types for the consumer</param> public static void UseConcurrentMessageLimit <TConsumer>(this IConsumerConfigurator <TConsumer> configurator, int concurrentMessageLimit) where TConsumer : class { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var observer = new ConcurrencyLimitConsumerConfigurationObserver <TConsumer>(configurator, concurrentMessageLimit); configurator.ConnectConsumerConfigurationObserver(observer); }
/// <summary> /// Limits the number of concurrent messages consumed by the consumer, regardless of message type. /// </summary> /// <param name="configurator"></param> /// <param name="concurrentMessageLimit">The concurrent message limit for all message types for the consumer</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 <TConsumer>(this IConsumerConfigurator <TConsumer> configurator, int concurrentMessageLimit, IManagementEndpointConfigurator managementEndpointConfigurator, string id = null) where TConsumer : class { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } if (managementEndpointConfigurator == null) { throw new ArgumentNullException(nameof(managementEndpointConfigurator)); } var observer = new ConcurrencyLimitConsumerConfigurationObserver <TConsumer>(configurator, concurrentMessageLimit, id); configurator.ConnectConsumerConfigurationObserver(observer); managementEndpointConfigurator.Instance(observer.Limiter, x => { x.UseConcurrentMessageLimit(1); x.Message <SetConcurrencyLimit>(m => m.UseRetry(r => r.None())); }); }