RabbitMQ

deshanjali diyasena
3 min readJul 22, 2020

Work Queue

RabbitMQ is a message broker application which is available free to use as open-source software. It is implemented based on the advanced message queue protocol (AMQP). The most common example that is used to explain RabbitMQ is the post office. Like in the post office this has the ability to take messages and put them in a queue and distribute them among receivers accordingly. In this RabbitMQ senders are known as producers and receivers are called consumers. You can see the basic architecture diagram of the RabbitMQ below:

https://www.rabbitmq.com/tutorials/tutorial-two-java.html

In RabbitMQ it always manages messages as binary blobs of data which can be transmitted from one application to another in a decoupled way. Those producer application and consumer application has independent roles in this RabbitMQ method that could be implemented using a different kind of technologies. RabbitMQ is bounded by the memory and disk limits of a host and also, we can say that a queue is actually a large message buffer which can receive messages from many producers. Most commonly used message broker is RabbitMQ but there are other brokers as well such as AWS SQS, RocketMQ, Kafka etc. Apart from AMQP, it supports HTTP, STOMP, MQTT protocols as well. When we consider benefits of RabbitMQ we can say that it has a highly available queue, build in management UI and tracing system supports many clients and clustering etc. RabbitMQ is built on Erlang runtime environment so in order to work with RabbitMQ we need to have Erlang in our machines.

Example:

I referred the sample code given in the RabbitMQ website and tried out the worker queue method using java client.

References: https://github.com/rabbitmq/rabbitmq-tutorials

https://www.rabbitmq.com/tutorials/tutorial-two-java.html

Added dependency and sample code

Mainly to execute this example we needed to download and install RabbitMQ and the erlang. Then we started the RabbitMQ service and also enabled the management UI. I used eclipse as the IDE to run the java client so as the first step, I got the relevant java maven project example and build it with the AMQP dependency. FIrstly had to compile NewTask file and Worker file with javac command. For the worker queue method, multiple workers should be running while tasks are generated and sent to the queue. In order to do that I used three terminals, one to generate tasks and the other two as workers. Final results are shown below how messages are divided when they stack to the queue.

starting RabbitMQ service and enable UI port
UI on port: 15672
Started two Workers
Task generator executed
Both workers receiving messages from the queue

--

--