RabbitMQ
This page shows you how to set up and use RabbitMQ from your lab. RabbitMQ is a message broker: one program publishes messages, other programs consume them, and the broker holds them in between. On this platform your messages live in virtual hosts (vhosts) — private namespaces for your exchanges and queues.
1. Create a user
- Go to Services and select Manage on RabbitMQ.
- Select Add User (or Create User if you have none yet).
- Fill in Username, Password and Confirm Password.
- Choose a User Privilege, then confirm.
| Privilege | Can | Use it for |
|---|---|---|
| Publish User | Configure, write and read — full access to your vhosts | Back-end code that publishes messages |
| Subscribe User | Configure and read — can consume but cannot publish | Code that only listens, including front-end code where the credentials could be seen |
Anyone holding a Publish User's password can write to your exchanges and queues. If credentials have to ship to a browser or a device you do not control, use a Subscribe User.
The username and password follow the same rules as for the other services. The username must be 5–16 characters of letters, digits and underscores. The password must be at least 8 characters, with no single quotes.
2. Create a virtual host
- Open the Virtual Host tab.
- Type a Virtual Host Name. It is prefixed with your platform username and an underscore, which are shown in front of the field.
- Select Create Virtual Host.
Virtual Hosts Usage shows how many you have used; the limit is 5. Every RabbitMQ user you create gets access to your virtual hosts, with the permissions of its privilege. Drop on a vhost card deletes it and everything in it.
3. Connect from your lab
The service card and the Connection Information panel list the host and the ports, each labeled with what it is for. Copy the AMQP host and port, then connect with any AMQP client:
amqp://<user>:<password>@<host>:<port>/<vhost>
<vhost> is the full name, including your prefix.
A minimal publisher in Python:
import pika # pip install pika
params = pika.URLParameters("amqp://<user>:<password>@<host>:<port>/<vhost>")
conn = pika.BlockingConnection(params)
ch = conn.channel()
ch.queue_declare(queue="tasks")
ch.basic_publish(exchange="", routing_key="tasks", body=b"hello")
conn.close()
And a consumer, which works with a Subscribe User once the queue exists:
import pika
params = pika.URLParameters("amqp://<user>:<password>@<host>:<port>/<vhost>")
conn = pika.BlockingConnection(params)
ch = conn.channel()
ch.basic_consume(queue="tasks", auto_ack=True,
on_message_callback=lambda c, m, p, body: print(body))
ch.start_consuming()
If it does not work
| Symptom | Check |
|---|---|
| ACCESS_REFUSED on sign-in | The username and password are copied from the card, and the vhost name includes your prefix |
| ACCESS_REFUSED when publishing | The user is a Subscribe User. Publish with a Publish User instead. |
| NOT_FOUND for a vhost | The vhost exists on the Virtual Host tab and you used its full name |