Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 37 Β· Getting Started

Installing and Running RabbitMQ

Install and start RabbitMQ with Docker or a package manager, learn the default ports and the guest user, and understand AMQP connection URIs.

You can run RabbitMQ on your laptop in about a minute. The easiest way is Docker, but native packages exist for every major system. This lesson shows the options, explains the ports you will see in every guide, and teaches you to read a connection URI.

The commands in the shell blocks below are read-only examples: they must be run on your own machine. The runnable blocks on this page are small Python stand-ins that explain ideas such as URIs and ports.

The official image rabbitmq comes in a plain flavor and a -management flavor that includes the web UI. Use the second one:

Terminal
docker run -d --name rabbit \
  -p 5672:5672 -p 15672:15672 \
  rabbitmq:4-management
  • -p 5672:5672 publishes the AMQP port your programs connect to.
  • -p 15672:15672 publishes the management web UI and HTTP API.
  • --name rabbit lets you stop and restart it by name.

Check that it started and look at the log:

Terminal
docker ps
docker logs rabbit

When the log says the broker is ready, open http://localhost:15672 in a browser. To stop and remove it:

Terminal
docker stop rabbit && docker rm rabbit

Data inside a container disappears when you remove it. For anything you want to keep, mount a volume on /var/lib/rabbitmq.

Option 2: native installs

  • Debian and Ubuntu: RabbitMQ publishes apt repositories. You need a compatible Erlang/OTP version, which the repositories also provide, and then apt install rabbitmq-server.
  • Fedora, RHEL and similar: use the official RPM repositories.
  • macOS: brew install rabbitmq, then brew services start rabbitmq.
  • Windows: install Erlang/OTP first, then the RabbitMQ installer, which registers a Windows service.

RabbitMQ is written in Erlang, which runs on the BEAM virtual machine. Native installs need a supported Erlang version; each RabbitMQ release documents which ones work. Docker avoids this by shipping both together.

Enable the management plugin

RabbitMQ has a plugin system. Plugins are switched on with rabbitmq-plugins:

Terminal
rabbitmq-plugins enable rabbitmq_management
rabbitmq-plugins list

Once enabled, the web UI is on port 15672. The -management Docker image already has it on.

Start, stop and check the node

On a native install the node is controlled by your service manager (systemctl start rabbitmq-server on most Linux systems). The tool rabbitmqctl talks to a running node:

Terminal
rabbitmqctl status
rabbitmqctl list_queues
rabbitmqctl stop_app
rabbitmqctl start_app

stop_app stops RabbitMQ inside the Erlang VM but leaves the VM running; stop stops the whole node. The CLI tools are covered in Management UI and CLI Tools.

The default user and the guest rule

A fresh broker has one user, guest, with password guest. For safety, RabbitMQ only lets guest connect from localhost. That is why a program on the same machine works, but a program on another machine gets an authentication error. For any real setup you create your own user:

Terminal
rabbitmqctl add_user app_user 'a-long-random-password'
rabbitmqctl set_permissions -p / app_user ".*" ".*" ".*"

The three patterns are configure, write and read permissions: regular expressions that say which resource names the user may create, publish to, and consume from. Never leave guest/guest reachable from the network.

Ports you will meet

Ports to remember

5672 AMQP 0-9-1 and AMQP 1.0 clients.
15672 Management UI and HTTP API.
5671 AMQP over TLS.
25672 Erlang distribution, for clustering.

Other protocols have their own ports, for example MQTT on 1883 and streams on 5552.

1 / 2

Firewalls should expose 5672 (or 5671) to your applications, 15672 only to administrators, and 25672 only between cluster nodes.

Virtual hosts

A virtual host (vhost) is a separate namespace inside one broker: its own exchanges, queues, bindings and permissions. The default vhost is /. Teams use vhosts to keep applications apart, for example /shop and /billing. A user must be granted permissions on each vhost it uses.

Terminal
rabbitmqctl add_vhost shop
rabbitmqctl set_permissions -p shop app_user ".*" ".*" ".*"

Reading a connection URI

Many clients accept one string that carries everything needed to connect. The format is an AMQP URI:

TEXT
amqp://user:password@host:5672/vhost

Because the default vhost is called /, which is a special character in a URL path, it must be written percent-encoded as %2F. The stand-in below uses Python's standard URL parser, so this part is real behavior, not simulation.

Python Taking apart AMQP URIs

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that /%2F decodes to the vhost named /, while /shop is a vhost called shop. Forgetting the encoding is a classic beginner error.

A tiny readiness check

A script that waits for the broker to be ready is common in Docker setups. Here is the logic, written against a fake "connection attempt" so it runs anywhere.

Python Retry until the broker is ready (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real client programs should do the same: brokers restart, networks blip, and a good client reconnects with backoff.

Check your understanding

Quick check Β· 4 questions

of 4 answered You scored / 4 Β· perfect!

  1. 1. Which port do applications use to talk AMQP to RabbitMQ by default?

    5672 is the AMQP port. 15672 is the management UI and 25672 is used between cluster nodes.
  2. 2. Why does the guest user fail when connecting from another machine?

    RabbitMQ restricts the default guest account to loopback connections for safety. Create a real user for remote access.
  3. 3. How do you write the default vhost "/" in an AMQP URI?

    A slash would be read as a path separator, so the vhost name "/" is percent-encoded as %2F.
  4. 4. What does a virtual host provide?

    Vhosts isolate resources inside one broker, so applications do not see each other's queues.

Summary

  • Docker image rabbitmq:4-management is the fastest way to start learning.
  • 5672 is AMQP, 15672 the management UI, 5671 AMQP over TLS and 25672 clustering.
  • The guest user works only from localhost; create real users with permissions.
  • Vhosts are isolated namespaces; in a URI the default vhost is %2F.
  • Clients should reconnect with backoff.

Next: Hello World: Publish and Consume