rabbitmq ready 一直为零

2020-12-05 08:06发布

消息发送后 客户端可以接收,但是rabbitmq 里Message rates下的状态有变化, ready/unacked/total 一直为0不变。

public void Register() {

        _channel.ExchangeDeclare(exchange: "exTest", type: "topic");
        _channel.QueueDeclare(queue: "queueTest", exclusive: false);
        _channel.QueueBind(queue: "queueTest", exchange: "exTest", routingKey: "t.key");

        var consumer = new EventingBasicConsumer(_channel);
        consumer.Received += (model, ea) => {
                var message = Encoding.UTF8.GetString(ea.Body.ToArray());
                var result = Process(message);
                if (result) {
                    _channel.BasicAck(ea.DeliveryTag, true); //返回消息确认
                }
        };

        _channel.BasicQos(0, 1, false);
       _channel.BasicConsume(queue: "queueTest", autoAck: false,  consumer: consumer);
    }

如果注释以下代码则 ready 可以正常统计。
_channel.BasicQos(0, 1, false);
_channel.BasicConsume(queue: "queueTest", autoAck: false, consumer: consumer);

1条回答
叛逆
2楼-- · 2020-12-05 08:22

你把_channel.BasicConsume(queue: "queueTest", autoAck: false, consumer: consumer);

这个autoAck设置为true试试
这个参数是是否收到消息应答服务器

查看更多
登录 后发表回答