In this article, we will be developing a RabbitMQ Consumer application for the Publisher application developed at previous article (named as part 1).
We have already developed a consumer application to consume the messages published by the above consumer application. In that consumer application we have focused on retrieving the publish messages manually. In other words, pulling the messages from the RabbitMQ queue whenever the client application needs them. If you need to look at that article, please click here.
In this article, we will be focusing on receiving the messages from queues with a listener. The consumer application will be listening for one or more queues for the incoming messages. whenever an incoming message is delivered to one of those queues, that message will be delivered to the consumer application through the listener (available in the consumer application).
This application is very much similar to the Consumer application we have developed or part 2 of this article series. Therefore all the configuration related classes will be same and i am not going to repeatedly explain them here. If you want know the further details, please refer the explanations in those articles.
The full source code of this application can be found at GitHub.
Open the source code directory called consumer-listener. In there you can see the source codes related to this article.
I will explain the most critical component here. That is the ConsumerService.
ConsumerService will be listening to two queues known as “all_cars_queue” and “nissan_cars_queue“. whenever a message is delivered to any of those queues, that message will be delivered to this consumer service class.