Getting start with RabbitMQ

Savin Abeysooriya
3 min readJul 22, 2020

Here is article about introduction about rabbitMQ and configuring rabbitMQ and create a simple messaging application using python.

RabbitMQ is a message broker. it accepts and forwards messages. Formally it was a Advanced Messaging Queuing protocol was developed in Erlang and OTP framework. It is open source and available for free. It can be accessed by multiple programming language such as Java, C#, PHP, Erlang, Python, Go, Ruby, JavaScript.

Basic components:

  • Producer
  • Consumer
  • Message
  • Exchange
  • Queue
  • Binding Key
  • Routing key

Producer: Application that sends the messages.

Consumer: Application that receives the messages.

Queue: Buffer that stores messages.

Message: Information that is sent from the producer to a consumer through RabbitMQ.

Exchange: Receives messages from producers and pushes them to queues depending on rules defined by the exchange type. To receive messages, a queue needs to be bound to at least one exchange.

Binding: A binding is a link between a queue and an exchange.

Routing key: A key that the exchange looks at to decide how to route the message to queues. Think of the routing key like an address for the message.

How to logging to rabbitMQ UI

First, you have to download and install erlang and rabbitmq-server to your machine. After installing you can run rabbitMQ server in your localhost, port 15672 and logging default credential “guest”.

Lets create a Work Queue using the Pika Python client that will be used to distribute time-consuming tasks among multiple workers.

prerequisites:

  • RabbitMQ is installed and running on localhost
  • installed pika (python -m pip install pika — upgrade)

First you have to create two files

  • new_task.py
  • worker.py

First, let’s try to run two worker.py scripts at the same time. They will both get messages from the queue. So you have to three consoles open. Two will run the worker.py script. These consoles will be our two consumers C1 and C2.

In the third one we’ll publish new tasks. Once you’ve started the consumers you can publish a few messages

consumer c1 and c2
publish new task

--

--