How to manually publish messages to RabbitMQ

May 28, 20252 min read

How to manually publish messages to RabbitMQ

Why would you want to manually send messages to RabbitMQ?

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.

Sending messages via code

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.

Publishing JSON messages to a specific RabbitMQ queue using RabbitGUI

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:

Json editor to publish messages to rabbitmq

Compared to the built-in RabbitMQ management plugin, RabbitGUI provides quite a few quality-of-life improvements, such as :

  • an actual JSON editor (same editor as VSCode) to help you format your messages
  • the ability to select where to publish your message based on available bindings
  • a history of all published messages, properly formatted and searchable

You can learn more about RabbitGUI here.

Using RabbitMQ management plugin to publish messages

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:

Rabbitmq management plugin send message screenshot

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:

Rabbitmq send message to excahnge via management plugin

More articles about RabbitMQ

RabbitMQ: maximum size of a messageRabbitMQ: maximum size of a messageThe maximum size of a message in RabbitMQ is not defined by the protocol, but by the implementation. Unfortunately, this value is not well documented and has changed a lot over timeHow to visually explore RabbitMQ queue bindingsHow to visually explore RabbitMQ queue bindingsThere are many ways messages can be routed to queues in RabbitMQ, and it can be hard to understand how they are connected in a single placeDebugging policies in RabbitMQDebugging policies in RabbitMQWhile rules regarding which policies are applied to which queues are simple, visually understanding what is going on when something does not behave as expected might be tricky

RabbitGUI, the missing RabbitMQ IDE

Debug, monitor, and manage RabbitMQ with a modern developer interface.

Try nowRabbitGUI screenshot