Esempio n. 1
0
        private async Task Process(ConsumerInfo consumer, ConsumerChild consumerChild, BasicDeliverEventArgs ea, int count)
        {
            if (count > 0)
            {
                await Task.Delay(count * 1000);
            }
            try
            {
                await consumer.Handler.Notice(ea.Body);

                if (!consumer.AutoAck)
                {
                    try
                    {
                        consumerChild.Channel.Model.BasicAck(ea.DeliveryTag, false);
                    }
                    catch
                    {
                        consumerChild.NeedRestart = true;
                    }
                }
            }
            catch (Exception exception)
            {
                logger.LogError(exception.InnerException ?? exception, $"An error occurred in {consumer.Exchange}-{consumer.Queue}");
                if (consumer.ErrorReject)
                {
                    consumerChild.Channel.Model.BasicReject(ea.DeliveryTag, true);
                }
                else
                {
                    if (count > 3)
                    {
                        consumerChild.NeedRestart = true;
                    }
                    else
                    {
                        await Process(consumer, consumerChild, ea, count + 1);
                    }
                }
            }
        }
Esempio n. 2
0
 private async Task InitModel(ConsumerInfo consumer)
 {
     if (consumer.Channel == default)
     {
         consumer.Channel = await client.PullModel();
     }
     else
     {
         if (consumer.Channel.Model.IsClosed)
         {
             consumer.Channel.Dispose();
             consumer.Channel = await client.PullModel();
         }
         else
         {
             return;
         }
     }
     consumer.Channel.Model.ExchangeDeclare(consumer.Exchange, "direct", true);
     consumer.Channel.Model.QueueDeclare(consumer.Queue, true, false, false, null);
     consumer.Channel.Model.QueueBind(consumer.Queue, consumer.Exchange, consumer.RoutingKey);
 }
Esempio n. 3
0
        private async Task ExpandQos(ConsumerInfo consumer)
        {
            if (consumer.NowQos + consumer.IncQos <= consumer.MaxQos)
            {
                var child = new ConsumerChild
                {
                    Channel = await client.PullModel(),
                    Qos     = consumer.IncQos
                };
                child.Channel.Model.BasicQos(0, consumer.IncQos, false);

                child.BasicConsumer           = new EventingBasicConsumer(child.Channel.Model);
                child.BasicConsumer.Received += async(ch, ea) =>
                {
                    await Process(consumer, child, ea, 0);
                };
                child.BasicConsumer.ConsumerTag = child.Channel.Model.BasicConsume(consumer.Queue, consumer.AutoAck, child.BasicConsumer);
                child.NeedRestart = false;
                consumer.Children.Add(child);
                consumer.NowQos   += child.Qos;
                consumer.StartTime = DateTime.UtcNow;
            }
        }