On a Ubuntu machine I'm unable to publish any messages to a RabbitMQ server exchange with a routing key or even directly to a queue.
The RabbitMQ server is running in a docker container and defined in a docker-compose file:
rabbitmq:
image: docker.io/bitnami/rabbitmq:3.11.23
ports:
- '4369:4369'
- '5551:5551'
- '5552:5552'
- '5672:5672'
- '25672:25672'
- '15672:15672'
environment:
RABBITMQ_SECURE_PASSWORD: no
RABBITMQ_LOGS: /bitnami/rabbitmq/mnesia/logs
RABBITMQ_PLUGINS: rabbitmq_management
RABBITMQ_USERNAME: ${BROKER_USER}
RABBITMQ_PASSWORD: ${BROKER_PASSWORD}
TZ: Europe/Amsterdam
volumes:
- 'rabbitmq_data:/bitnami/rabbitmq/mnesia'
expose:
- 4369
- 5551
- 5552
- 5672
- 25672
- 15672
networks:
- broker
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:15672"]
interval: 5s
timeout: 5s
retries: 10
restart: always
The NodeJs service is running in a different container in a Alpine image. The service does connect to the RabbitMQ server and creates all the necessary exchanges, bindings and queues. So the connection is OK. I've also added a user test
with password test
.
In the management console I've setup a queue named all
with a routing key #
so it receives all messages. I use the following NodeJS test script to publish to that exchange:
const amqp = require('amqplib');
const message = {
message: 'world',
};
async function connectAndPublish() {
try {
// Connect to RabbitMQ server
const connection = await amqp.connect('amqp://test:test@rabbitmq:5672/');
const channel = await connection.createChannel();
// Declare exchange
const exchangeName = 'the-exchange';
await channel.assertExchange(exchangeName, 'topic', { durable: true });
// Convert message to JSON and publish to the exchange
const messageBuffer = Buffer.from(JSON.stringify(message));
channel.publish(exchangeName, 'hello', messageBuffer);
console.log(`Message published to exchange ${exchangeName}:`, message);
// Close connection
await channel.close();
await connection.close();
} catch (error) {
console.error('Error:', error.message);
}
}
// Call the function to connect and publish
connectAndPublish();
The script connects to the RabbitMQ server. When I change the username I get an authentication error, so the connection is ok.
However no message is being delivered to the all
queue. In the management console there is not even a flow of message visible.
Things I've tried:
- Upgrade/downgrade the RabbitMQ server (3.11. or 3.12)
- Publish directly to the
all
queue instead of the exchange with a routing key - Restarted the docker containers
It worked yesterday but it suddenly stopped working today.
The logs of RabbitMQ only shows that the user test is authenticated, there are no errors or warnings.
The NodeJs script creates the exchange but somehow not a single message arrives.
All the docker containers are being manager in portainer.
What could be the cause of this?