chevron-up bell reply instagram twitter2 feed3 finder search-25px-p0

Get Start with RabbitMQ

2017-09-01

RabbitMQ is an open source & enterprise level messsage broker using AMQP protocal. The AMQP protocol is designed for asychronization and message dispatch. RabbitMQ can be used in time-consuming backend jobs such as sending emails to client, generating file for user to download, and so on.

Install on Mac

Then install the client Pika for RabbitMQ

Start RabbitMQ

Consumer & Producer Problem

In parallel programming, Consumer & Producer Problem refers to one type of the most frequently used cases. Simply, Producers create data in a fixed size cache, while Consumers would take data from that cache. To make the whole process working properly, it is a must that producers would not produce new data while the cache is full, and consumers will not take more when the cache is empty.

VHOST (Virtual host) in RabbitMQ

Vhost is an important concept in RabbitMQ, which you can create queue, binding and exchange seperately. By default, RabbitMQ comes with a inner-built vhost named '/'. However we need more vhosts, queues to organize our tasks when there are too many. Just like in programing we have different naming space and modules.

🙋 Create a new user with name ben and password 1234

🙋 Create a new vhost

🙋 Set permissions on the new vhost

1st ".*" means enable user ben to add and delete Queue and Exchange
2nd ".*" means enable user ben to publish new messages
3rd ".*" means enable user ben to read new messages

🙋 Now we can gete all the vhosts in current system:

Results:

🙋 Sure thing we can list all the queues in a vhost

Results:

🙋 There is also an additional cmd to get all the users:

Results:


Show me the code!

The following is an example of

Libraries in use:

  • pika

rabbitmq_producer.py

rabbitmq_consumer.py

Run with consumer first, python rabbitmq_consumer.py

The run python rabbitmq_producer.py msg in another terminal. You would find out a new message showing up from consumer terminal.


Update

By default, RabbitMQ provides a default account with Guest/Guest with admin privilege. When publishing to production, password must be changed!


Reference

http://www.arkilis.me/
https://github.com

arkilis

Comments: