Skip to main content

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​

  1. Go to Services and select Manage on RabbitMQ.
  2. Select Add User (or Create User if you have none yet).
  3. Fill in Username, Password and Confirm Password.
  4. Choose a User Privilege, then confirm.
Shown on labs.selfmade.ninja, the Selfmade Ninja Academy platform. On your own platform you will see your own domain and data.
PrivilegeCanUse it for
Publish UserConfigure, write and read — full access to your vhostsBack-end code that publishes messages
Subscribe UserConfigure and read — can consume but cannot publishCode that only listens, including front-end code where the credentials could be seen
Keep publish credentials on the server side

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​

  1. Open the Virtual Host tab.
  2. Type a Virtual Host Name. It is prefixed with your platform username and an underscore, which are shown in front of the field.
  3. 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​

SymptomCheck
ACCESS_REFUSED on sign-inThe username and password are copied from the card, and the vhost name includes your prefix
ACCESS_REFUSED when publishingThe user is a Subscribe User. Publish with a Publish User instead.
NOT_FOUND for a vhostThe vhost exists on the Virtual Host tab and you used its full name

Next​