RabbitMQ – installing and managing a message broker

Describes how to install and manage the RabbitMQ message broker.

This article is related to the article Flask, Celery + RabbitMQ. Was placed in a separate article due to the amount of information.

What is RabbitMQ for?

RabbitMQ Is a “message broker”, in other words, something like a postal service. It accepts messages (tasks), processes the queue of these tasks and sends the result (for example, saving it to the database).

IN Rediswhich is an in-memory data store service also has a message broker. However, RabbitMQ was built from start to finish just for this purpose. But if you already have Redis installed on the server, then it probably makes more sense to use it rather than add additional dependencies.

Installing RabbitMQ on Mac OS

Before sending our postman to work on the production server, we need to debug all this somewhere. Because I am using Mac OS, then I will describe the installation process on this operating system.

Like all third party packages on Mac OS, RabbitMQ is installed via the Homebrew package manager.

Installation:

brew update
brew install rabbitmq

Then you need to run it:

brew services start rabbitmq

Add environment variable before entering commands on Mac OS. Otherwise, there will be errors:

zsh: command not found: rabbitmqctl

To correct, enter:

export PATH=$ PATH:/usr/local/opt/rabbitmq/sbin

If you need to reboot your rabbit:

brew services restart rabbitmq

Installing RabbitMQ on Ubuntu 20.04

sudo apt update
sudo apt install rabbitmq-server

After installation, the RabbitMQ server will start automatically and will also be added to startup.

Check status:

systemctl status rabbitmq-server.service

All commands for RabbitMQ on Linux must be entered either from the root user or via sudo.

rabbitmq_management

rabbitmq_management Is a web-based RabbitMQ queue management panel.

Rabbitmq must be off before activating the web panel.

By default login and password guest… There is no need to change this user or password for it. It is only available on localhost.

Mac OS

Panel activation:

/usr/local/sbin/rabbitmq-plugins enable amqp_client

Local address:

Linux

Activation:

sudo rabbitmq-plugins enable rabbitmq_management

Server address:

http: // {site or IP}: 15672 /

If the ufw firewall is configured, then open the ports for it:

sudo ufw allow proto tcp from any to any port 5672,15672

Add a new user:

sudo rabbitmqctl add_user user_ploshadka.net password

Add it to the admin group:

sudo rabbitmqctl set_user_tags user_ploshadka.net administrator

Change username and password through the web panel

You can change it here:

When changing the username and password, you should also change it in the constant of the flask configuration file:

CELERY_BROKER_URL = ‘pyamqp: // guest: @ dsfdK554fsm @ localhost //’

Errors

When changing the login and password in the team celery inspect registered an error may occur:

amqp.exceptions.AccessRefused: (0, 0): (403) ACCESS_REFUSED – Login was refused using authentication mechanism AMQPLAIN. For details see the broker logfile.

The guest user and password should not be changed. It is used for server authentication. With this data, you can only enter localhost… Create a separate user to log in on production.

Change username and password through the console

rabbitmqctl add_user ploshadka.net dsfdK554fsm
rabbitmqctl add_vhost rabbit
rabbitmqctl set_user_tags ploshadka.net administrator
rabbitmqctl set_permissions -p rabbit ploshadka.net “. *” “. *” “. *”

Useful commands

Stop processes:

Show users:

Delete user:

rabbitmqctl delete_user user

Change user password:

rabbitmqctl change_password user password

Create a new virtualhost:

rabbitmqctl add_vhost /my_vhost

Show available virtual hosts:

Remove virtual host:

rabbitmqctl delete_vhost /hostname

Assign rights to virtual host:

rabbitmqctl set_permissions -p /hostname user “. *” “. *” “. *”

List of rights:

rabbitmqctl list_permissions -p /hostname

Show user rights:

rabbitmqctl list_user_permissions user

Remove user rights:

rabbitmqctl clear_permissions -p /hostname user

How to clear the queue from celery

Stop rabbitmqct then go to your project directory.

cd
celery pyamqp queue.purge <queue name>
sudo rabbitmqctl start

Reset everything to default

Completely reset all bunny settings:

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *