예제 #1
0
 private void BuildConsumers()
 {
     foreach (var consumerSetting in Options.ConsumerOptions)
     {
         if (!string.IsNullOrEmpty(consumerSetting.Value.ConsumerPipelineOptions.ConsumerPipelineName))
         {
             ConsumerPipelineNameToConsumerOptions.TryAdd(consumerSetting.Value.ConsumerPipelineOptions.ConsumerPipelineName, consumerSetting.Value);
         }
         Consumers.TryAdd(consumerSetting.Value.ConsumerName, new Consumer(ChannelPool, consumerSetting.Value));
     }
 }
        private void ConsumeFromQueue(string queue)
        {
            var consumer    = new InternalConsumer(this, Channel, queue);
            var consumerTag = Channel.BasicConsume(
                queue,
                AcknowledgeMode.IsAutoAck(),
                TagStrategy != null ? TagStrategy.CreateConsumerTag(queue) : string.Empty,
                NoLocal,
                Exclusive,
                ConsumerArgs,
                consumer);

            if (consumerTag != null)
            {
                Consumers.TryAdd(queue, consumer);
                Logger?.LogDebug("Started on queue '{queue}' with tag {consumerTag} : {consumer}", queue, consumerTag, ToString());
            }
            else
            {
                Logger?.LogError("Null consumer tag received for queue: {queue} ", queue);
            }
        }
예제 #3
0
        private void BuildConsumers()
        {
            foreach (var consumerSetting in Config.ConsumerSettings)
            {
                // Apply the global consumer settings and global consumer pipeline settings
                // on top of (overriding) individual consumer settings. Opt out by not setting
                // the global settings field.
                if (!string.IsNullOrWhiteSpace(consumerSetting.Value.GlobalSettings) &&
                    Config.GlobalConsumerSettings.ContainsKey(consumerSetting.Value.GlobalSettings))
                {
                    var globalOverrides = Config.GlobalConsumerSettings[consumerSetting.Value.GlobalSettings];

                    consumerSetting.Value.NoLocal =
                        globalOverrides.NoLocal
                        ?? consumerSetting.Value.NoLocal;

                    consumerSetting.Value.Exclusive =
                        globalOverrides.Exclusive
                        ?? consumerSetting.Value.Exclusive;

                    consumerSetting.Value.BatchSize =
                        globalOverrides.BatchSize
                        ?? consumerSetting.Value.BatchSize;

                    consumerSetting.Value.AutoAck =
                        globalOverrides.AutoAck
                        ?? consumerSetting.Value.AutoAck;

                    consumerSetting.Value.UseTransientChannels =
                        globalOverrides.UseTransientChannels
                        ?? consumerSetting.Value.UseTransientChannels;

                    consumerSetting.Value.ErrorSuffix =
                        globalOverrides.ErrorSuffix
                        ?? consumerSetting.Value.ErrorSuffix;

                    consumerSetting.Value.BehaviorWhenFull =
                        globalOverrides.BehaviorWhenFull
                        ?? consumerSetting.Value.BehaviorWhenFull;

                    if (globalOverrides.GlobalConsumerPipelineSettings != null)
                    {
                        if (consumerSetting.Value.ConsumerPipelineSettings == null)
                        {
                            consumerSetting.Value.ConsumerPipelineSettings = new Configs.ConsumerPipelineOptions();
                        }

                        consumerSetting.Value.ConsumerPipelineSettings.WaitForCompletion =
                            globalOverrides.GlobalConsumerPipelineSettings.WaitForCompletion
                            ?? consumerSetting.Value.ConsumerPipelineSettings.WaitForCompletion;

                        consumerSetting.Value.ConsumerPipelineSettings.MaxDegreesOfParallelism =
                            globalOverrides.GlobalConsumerPipelineSettings.MaxDegreesOfParallelism
                            ?? consumerSetting.Value.ConsumerPipelineSettings.MaxDegreesOfParallelism;

                        consumerSetting.Value.ConsumerPipelineSettings.EnsureOrdered =
                            globalOverrides.GlobalConsumerPipelineSettings.EnsureOrdered
                            ?? consumerSetting.Value.ConsumerPipelineSettings.EnsureOrdered;
                    }
                }

                if (!string.IsNullOrEmpty(consumerSetting.Value.ConsumerPipelineSettings.ConsumerPipelineName))
                {
                    ConsumerPipelineNameToConsumerSetting.TryAdd(consumerSetting.Value.ConsumerPipelineSettings.ConsumerPipelineName, consumerSetting.Value);
                }
                Consumers.TryAdd(consumerSetting.Value.ConsumerName, new Consumer(ChannelPool, consumerSetting.Value, _hashKey));
            }
        }