【问题标题】:RabbitMQ consumers die in dockerized environment but not in devRabbitMQ 消费者在 dockerized 环境中死亡,但在开发环境中没有
【发布时间】:2022-10-15 21:43:47
【问题描述】:

希望大家周末愉快,我有以下订阅方法

public void Subscribe(string queueName, Func<string, Task<bool>> onMessageReceived, Action<Exception> onError)
{
    var channel = _connection.CreateModel();
    channel.QueueDeclare(queueName, false, false, false, null);
    var consumer = new EventingBasicConsumer(channel);
    //receive only one message at a time and wait for the method to return before receiving the next message
    channel.BasicQos(0, 1, false);
    consumer.Received += async (model, ea) =>
    {
        var body = ea.Body.ToArray();
        var message = Encoding.UTF8.GetString(body);
        try
        {
            Console.WriteLine(" [x] Received {0} , consumer-id {1}", message, ea.ConsumerTag);
            if (!await onMessageReceived(message))
            {
                throw new Exception("Message processing failed");
            }
            channel.BasicAck(ea.DeliveryTag, false);
        }
        catch (Exception e)
        {
            onError(e);
            channel.BasicNack(ea.DeliveryTag, false, true);
        }
    };
    channel.BasicConsume(queueName, false, consumer);
}

在我的开发环境中运行良好,问题是当我在 Docker 机器上旋转这个坏男孩的一些实例时,它们似乎在大约 30 分钟后死亡,没有错误,没有任何东西,执行继续但没有收到消息,它们从 rabbitMQ 中消失消费者数组。

我错过了什么?

【问题讨论】:

    标签: c# rabbitmq


    【解决方案1】:

    消费者应改为

    var consumer = new AsyncEventingBasicConsumer(channel);
    

    工厂应该有参数

    factory.DispatchConsumersAsync = true;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多