May 28, 2025•2 min read
Good question. Sometimes you just need to test something quickly, you want to trigger a specific job, or you want to retry a task that failed. All of those are valid reasons to manually publish a message to RabbitMQ. What sounds like a dead simple task is actually more painful than you might think. In this article we will go over some ways to publish messages directly to RabbitMQ, from painful to effortless using RabbitGUI.
While this is not the most practical solution, it is still a solution in case you have nothing else. To publish a message in RabbitMQ using JavaScript, you’ll typically use the amqplib library. First, install the library:
npm install amqplib
Then, run a script like this:
import amqplib from 'amqplib';
const conn = await amqplib.connect('amqp://localhost');
const ch = await conn.createChannel();
ch.publish(
'my-exchange',
'my.routing.key',
Buffer.from(JSON.stringify({ foo: 'bar' }))
);
This example connects to RabbitMQ, creates a channel, and sends a JSON-encoded message to it. Pretty straight forward and might do the trick if you need to connect to an external API or do some computation before sending the messages.
The simplest approach is to use RabbitGUI, which allows you to publish messages to a specific queue or exchange with just a few clicks and a real JSON editor for ease of use. Go to any queue and go to the "Publish" tab:
Compared to the built-in RabbitMQ management plugin, RabbitGUI provides quite a few quality-of-life improvements, such as :
You can learn more about RabbitGUI here.
You can use the management plugin to publish messages to RabbitMQ. There are two ways to do so: either to a specific queue or to an exchange. To send a message to a specific queue, go to the "Queues" tab in the management plugin, select the queue you want to send a message to, and unfold the "Publish message" section. You can then enter the message body and properties:
Note that the message will be sent to the default exchange with the name of the queue as the routing key, which means that it will be routed to the queue you selected. If you want to send a message to an exchange, go to the "Exchanges" tab, select the exchange you want to send a message to, and unfold the "Publish message" section. You can then enter the message body and properties:
Debug, monitor, and manage RabbitMQ with a modern developer interface.
Try now