What RabbitMQ does
RabbitMQ is an open-source message broker (MPL-2.0 licence) written in Erlang. Applications send it messages over the AMQP protocol; it stores them in queues, keeps them on disk when asked to, and hands them to consumers that acknowledge them once processed. An unacknowledged message — because the worker crashed — is redelivered to another one. Between the application and the queues, exchanges route each message to one queue, several, or every queue subscribed to it.
What RabbitMQ gives you
- Pages that answer fast — slow tasks go to a queue instead of blocking the request.
- No lost jobs — durable queues and acknowledgements: a crashing worker makes nothing disappear.
- Spikes absorbed — messages wait in the queue while workers catch up.
- Decoupled services — an event published once, received by every service that needs it.
- A web console — queues, rates, consumers and pending messages at a glance.
- Every language — PHP, Python, Java, Node.js, .NET, Go and Ruby all have an AMQP client.
Redis, RabbitMQ or Kafka for your messages
Scroll the table
| Redis (list or stream) | RabbitMQ | Kafka | |
|---|---|---|---|
| Typical use | Cache, small job queue | Job queues and event routing | Very high-volume event log |
| Acknowledgement and redelivery | Handled in the application | Built in | Through read offsets |
| Routing | Simple | Direct, topic, fanout, headers exchanges | By topic and partition |
| Management console | None out of the box | Included (management plugin) | Third-party tools |
| Memory at rest | A few MB | About 150 MB | Often more than 1 GB |
Prepare the server
An Ubuntu 24.04 VPS with 2 GB of RAM suits most projects: RabbitMQ uses about 150 MB at rest, and it often shares the machine with the application and its workers. Install Docker and the Compose plugin, and plan a subdomain, for example rabbitmq.example.com, pointing to the VPS: the management console must be served over HTTPS, since passwords travel through it. The AMQP port will never be published to the Internet.
Install RabbitMQ with Docker Compose
Prepare the folder and the .env file
A single secret: the password of the
adminaccount, created on first start.mkdir -p /opt/rabbitmq && cd /opt/rabbitmq cat > .env <<EOF RABBITMQ_PASSWORD=$(openssl rand -hex 16) EOF chmod 600 .envWrite the docker-compose.yml file
A single service, the official image with the management console. Both ports are only published on the loopback: the console (15672) will go through nginx, and AMQP (5672) stays reserved for the VPS. The fixed
hostnamematters: RabbitMQ stores its data under its node name, and a container recreated under another name would start from an empty database.services: rabbitmq: image: rabbitmq:4.4-management-alpine hostname: rabbitmq restart: unless-stopped ports: - "127.0.0.1:15672:15672" - "127.0.0.1:5672:5672" environment: RABBITMQ_DEFAULT_USER: admin RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD} volumes: - rabbitmq-data:/var/lib/rabbitmq networks: - rabbitmq healthcheck: test: ["CMD", "rabbitmq-diagnostics", "-q", "check_port_connectivity"] interval: 30s timeout: 10s retries: 5 networks: rabbitmq: name: rabbitmq volumes: rabbitmq-data: {}Start and check
RabbitMQ answers in about fifteen seconds. The console API must return
200with theadminaccount, and401without it.docker compose up -d docker compose ps curl -s -o /dev/null -w '%{http_code}\n' -u admin:"$(grep RABBITMQ_PASSWORD .env | cut -d= -f2)" \ http://127.0.0.1:15672/api/overviewCheck the account and the node
Only
adminshould be listed: as soon asRABBITMQ_DEFAULT_USERis set, the factoryguestaccount is not created.docker compose exec rabbitmq rabbitmqctl list_users docker compose exec rabbitmq rabbitmq-diagnostics status | head -n 20
Keep AMQP private and one user per application
Never publish port 5672 on 0.0.0.0: your applications reach it through the loopback or the Docker network, and an exposed broker attracts login attempts. And never give the admin account to an application: create its own vhost and user (next section), so that a leak stays confined to its space.
Publish the console over HTTPS behind nginx
Get a certificate with certbot (certbot certonly --nginx -d rabbitmq.example.com), then declare a server block that forwards to local port 15672. The console and its API share the same address.
server {
listen 443 ssl;
server_name rabbitmq.example.com;
ssl_certificate /etc/letsencrypt/live/rabbitmq.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/rabbitmq.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:15672;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
}
}Create one vhost and one user per application
A virtual host is a sealed space: its queues, exchanges and permissions see nothing of the others. Create one per application, with a user that only has permissions on it. The same can be done in the Admin tab of the console.
docker compose exec rabbitmq rabbitmqctl add_vhost shop
docker compose exec rabbitmq rabbitmqctl add_user app-shop '<long-password>'
docker compose exec rabbitmq rabbitmqctl set_permissions -p shop app-shop ".*" ".*" ".*"
docker compose exec rabbitmq rabbitmqctl list_permissions -p shopConnect Laravel, Django or Node.js
An application installed directly on the VPS connects to 127.0.0.1:5672. For Laravel, the laravel-queue-rabbitmq package adds a queue driver; php artisan queue:work rabbitmq then starts the workers.
composer require vladimir-yuldashev/laravel-queue-rabbitmq
# application .env
QUEUE_CONNECTION=rabbitmq
RABBITMQ_HOST=127.0.0.1
RABBITMQ_PORT=5672
RABBITMQ_USER=app-shop
RABBITMQ_PASSWORD=<long-password>
RABBITMQ_VHOST=shopCelery, with Django or on its own, takes an AMQP URL. An application running in a container joins the rabbitmq network and targets the service name instead of 127.0.0.1. Node.js (amqplib), Spring AMQP or .NET accept the same URL.
# settings.py (Django + Celery)
CELERY_BROKER_URL = "amqp://app-shop:<long-password>@127.0.0.1:5672/shop"
# containerised application: join the RabbitMQ network
docker network connect rabbitmq my-worker
# then amqp://app-shop:<long-password>@rabbitmq:5672/shopWatch the queues
A queue that keeps growing signals workers that are too slow or stopped. The console shows it in the Queues tab; on the command line, the same reading fits in one line: ready messages, messages being processed and number of consumers per queue.
docker compose exec rabbitmq rabbitmqctl list_queues name messages_ready messages_unacknowledged consumersFor long-term monitoring, the rabbitmq_prometheus plugin is already enabled in the official image: it serves its metrics on port 15692 of the container. Publish it as 127.0.0.1:15692:15692 and add it to the Prometheus targets to follow the queues in Grafana.
Backup and upgrade
The whole state of RabbitMQ lives in the rabbitmq-data volume. Also export its definitions — users, vhosts, queues, exchanges and permissions — to a JSON file: that is what rebuilds a broker in seconds, with rabbitmqctl import_definitions.
cd /opt/rabbitmq
docker compose exec rabbitmq rabbitmqctl export_definitions /tmp/definitions.json
docker compose cp rabbitmq:/tmp/definitions.json ./definitions-$(date +%F).jsonBefore moving to a new series, enable the feature flags of the running version, read the release notes, then change the image tag and restart:
docker compose exec rabbitmq rabbitmqctl enable_feature_flag all
docker compose pull && docker compose up -dRabbitMQ in one click on ServOrbit
The ServOrbit Marketplace installs exactly this stack: the official rabbitmq image with its console, an admin account created with a generated password, the console published over HTTPS on a subdomain of your domain or on the VPS's free subdomain, and the AMQP port kept on the loopback. The password is shown in your client area; all that is left is to create your vhosts and connect your workers.
servorbit.com/ma-en/blog/self-host-rabbitmq-vps-message-broker
