How To Monitor RabbitMQ Messages

How do you watch RabbitMQ messages without consuming them?

You may find yourself needing to live monitor messages from a web page as they are being processed through RabbitMQ. This can be useful to monitor a logging message queue, obtain the processing status of a system as it’s state changes, etc. Here, we’ll explore an approach to getting this done. Even better, we’ll do this with pure HTML and javascript for a light-weight front-end only approach, leaving server backend code, behind.

RabbitMQ, WebSockets & WebStomp

To be able to make RabbitMQ subscriptions and view live updates through javascript, we’ll need to make use of WebSocket and fortunately, the RabbitMQ Web-Stomp Plugin is available for this purpose.

Installing RabbitMQ WebStomp Plugin

The plugin is included with RabbitMQ so if you already have RabbitMQ on your server, you can enable the RabbitMQ WebStomp Plugin with this command:

rabbitmq-plugins enable rabbitmq_web_stomp

A Basic Example

Here we’ll include stomp.js and jquery.tiny-pubsub so we can publish the messages as they arrive and subscribe to them in a script elsewhere.

Notice that the client.subscribe is pointing to an exchange endpoint not a queue endpoint and we’ve added a ‘reply-to’ header set up a temporary queue. This will prevent the messages from being consumed here and preventing the application that is handling them from processing them. This will also allow multiple instances of this page to monitor without loosing the messages because they were consumed in another location.