获取 RabbitMQ 队列中的消息数

Getting number of messages in a RabbitMQ queue(获取 RabbitMQ 队列中的消息数)
本文介绍了获取 RabbitMQ 队列中的消息数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我们使用 amqplib 来发布/使用消息.我希望能够读取队列上的消息数量(理想情况下,既已确认又未确认).这将允许我向管理员用户显示一个漂亮的状态图,并检测某个组件是否跟不上负载.

We're using amqplib to publish/consume messages. I want to be able to read the number of messages on a queue (ideally both acknowledged and unacknowledged). This will allow me to show a nice status diagram to the admin users and detect if a certain component is not keeping up with the load.

我在 amqplib 文档中找不到任何关于读取队列状态的信息.

I can't find any information in the amqplib docs about reading queue status.

有人能指出正确的方向吗?

Can someone point me in the right direction?

推荐答案

使用鼠兔:

import pika

pika_conn_params = pika.ConnectionParameters(
    host='localhost', port=5672,
    credentials=pika.credentials.PlainCredentials('guest', 'guest'),
)
connection = pika.BlockingConnection(pika_conn_params)
channel = connection.channel()
queue = channel.queue_declare(
    queue="your_queue", durable=True,
    exclusive=False, auto_delete=False
)

print(queue.method.message_count)

使用 PyRabbit:

from pyrabbit.api import Client
cl = Client('localhost:55672', 'guest', 'guest')
cl.get_messages('example_vhost', 'example_queue')[0]['message_count']

使用 HTTP

语法:

curl -i -u user:password http://localhost:15672/api/queues/vhost/queue

例子:

curl -i -u guest:guest http://localhost:15672/api/queues/%2f/celery           

注意:默认虚拟主机是 / 需要转义为 %2f

Note: Default vhost is / which needs to be escaped as %2f

使用 CLI:

$ sudo rabbitmqctl list_queues | grep 'my_queue'

这篇关于获取 RabbitMQ 队列中的消息数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Seasonal Decomposition of Time Series by Loess with Python(Loess 用 Python 对时间序列进行季节性分解)
Resample a time series with the index of another time series(使用另一个时间序列的索引重新采样一个时间序列)
How can I simply calculate the rolling/moving variance of a time series in python?(如何在 python 中简单地计算时间序列的滚动/移动方差?)
How to use Dynamic Time warping with kNN in python(如何在python中使用动态时间扭曲和kNN)
Keras LSTM: a time-series multi-step multi-features forecasting - poor results(Keras LSTM:时间序列多步多特征预测 - 结果不佳)
Python pandas time series interpolation and regularization(Python pandas 时间序列插值和正则化)