This is an asyncio RabbitMQ monitor API for Python3.12+.
It wraps the RabbitMQ management plugin REST api. This allows retrieving metrics and peeking into the queues.
This is work in progress, but is functional.
This can be installed with pip.
Multiple clients a supported and one must be selected. Choose one of:
pip install jetblack-rabbitmqmon[bareclient]Or alternatively:
pip install jetblack-rabbitmqmon[aiohttp]The following gets an overview using the httpx.
import asyncio
from jetblack_rabbitmqmon.monitor import Monitor
from jetblack_rabbitmqmon.clients.httpx_requester import HttpxRequester
async def main_async():
mon = Monitor(
BareRequester(
'http://mq.example.com:15672',
'admin',
'admins password'
)
)
overview = await mon.overview()
print(overview)
if __name__ == '__main__':
asyncio.run(main_async())The follow explores a vhost using the aiohttp client.
import asyncio
from jetblack_rabbitmqmon.monitor import Monitor
from jetblack_rabbitmqmon.clients.aiohttp_requester import AioHttpRequester
async def main_async():
mon = Monitor(
AioHttpRequester(
'http://mq.example.com:15672',
'admin',
'admins password'
)
)
vhosts = await mon.vhosts()
for vhost in vhosts.values(): # vhost is a dict
exchanges = await vhost.exchanges()
for exchange in exchanges.values(): # exchanges is a dict
print(exchange)
# Objects can be refreshed to gather new metrics.
await exchange.refresh()
print(exchange)
bindings = await exchange.bindings()
for binding in bindings:
print(binding)
if __name__ == '__main__':
asyncio.run(main_async())The following gets some messages from an exchange using the httpx client.
import asyncio
from jetblack_rabbitmqmon.monitor import Monitor
from jetblack_rabbitmqmon.clients.httpx_requester import HttpxRequester
async def main_async():
mon = Monitor(
HttpxRequester(
'http://mq.example.com:15672',
'admin',
'admins password'
)
)
vhosts = await mon.vhosts()
vhost = vhosts['/some-vhost']
queues = await vhost.queues()
queue = queues['some.queue']
messages = await queue.get_messages()
print(messages)
if __name__ == '__main__':
asyncio.run(main_async())To test, start rabbit as a container.
# latest RabbitMQ 4.x
podman run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4-management