(Using Celery with Flask and RabbitMQ)
Ubuntu 18.04
Install:
$ sudo apt-get install rabbitmq-server
- Check status by
$ systemctl status rabbitmq-server.service
- Check enablity by
$ systemctl is-enabled rabbitmq-server.service
- If disabled, enable it by
$ sudo systemctl enable rabbitmq-server
- Enable rabbitmq management dashboard by
$ sudo rabbitmq-plugins enable rabbitmq_management
- It should be listening TCP port 15672
$ sudo ss -tunelp | grep 15672
- Add new user by
$ sudo rabbitmqctl add_user <admin> <mypassword>
- Add virtual host by
$ sudo rabbitmqctl add_vhost <myvhost>
- Add user tag by
$ sudo rabbitmqctl set_user_tags <admin> <mytag>
- Set permission by
$ sudo rabbitmqctl set_permissions -p <myvhost> <admin> ".*" ".*" ".*"
To start the server: $ sudo rabbitmq-server
To stop the server: $ sudo rabbitmqctl stop
- Clone this repository.
- Create a virtualenv and install the requirements.
$ virtualenv venv
,$ source venv/bin/activate
and$ pip3 install -r requirements.txt
. - Open a terminal window and start a local RabbitMQ server.
- Open the second terminal window. Start a Celery worker:
$ celery worker -A wsgi_app.celery --loglevel=info --pool=solo
. - Start the third terminal window for your application:
$ python3 wsgi_app.py
. - Go to
http://localhost:5000/
and enjoy this application!
- Install flower
$ pip3 install flower
- Open a terminak window and launch flower
$ celery flower --port=5566
- (Optional) Specify Celery application path with address and port for Flower:
$ celery -A proj flower --address=127.0.0.6 --port=5566
- Open the UI at
http://localhost:5566