我可以通过 AMQP 客户端查看 RabbitMQ 中未确认消息的计数吗?

Can I see the count of unacked messages in RabbitMQ via an AMQP client?

在 RabbitMQ web UI 中,我可以看到,对于每个队列,准备使用的消息数和正在处理但尚未确认的消息数。

但是,我看不到如何通过 AMQP 客户端获取未确认消息的数量。

例如,AMQP.Queue.message_count/2 function in the Elixir client uses the underlying Erlang librarypassive: true重新声明队列并返回message_countconsumer_count字段,但message_count包括仅“准备好发送(例如,未等待确认)”的消息。

我的目标是查看目前有多少消息积压。出于我的目的,当前正在处理的那些与准备好处理的那些一样多。

如何使用 AMQP 客户端获取给定 RabbitMQ 队列的未确认 消息的计数?

AMQP 0.9-1 does not have that information in the Declare-OK message, nor do I see that in RabbitMQ's AMQP extensions.

如果您的消费者相似,您可以使用近似值 Total = Ready + ConsumerCount * QoS(QoS 是每个消费者的预取计数),考虑到如果 Ready == 0,则近似值是上限(因为代理可能没有足够的消息来满足所有消费者)。

您还有另一种选择,即使用管理插件通过 REST API

提供的统计信息