RabbitMQ - Getting Started with RabbitMQ

Before you can understand what RabbitMQ (message queue) is, it's helpful to see how data is transmitted without RabbitMQ. In this extremely simplified diagram, the sending system (producer) transmits data to the receiving system (consumer). In this scenario, the data would most probably be in XML format, and be something like an order placed at an online store.

While this is all fine and dandy, this type of design can produce problems. Most notably, if the receiving system is unable to receive the data (eg. the receving system is down or overwhelmed with requests), the sending system may not be able to move onto the next transmission or may continually try to send the data over and over again (which is a waste of the sending systems resources). RabbitMQ resolves these issues.

 

RabbitMQ sit's between the sending system (producer) and receiving system (consumer), as a sort of broker or proxy. In this way, if the receiving system is unavailable, the sending system does not get trapped in a situation where it cannot move onto it's next transmission or is bogged down trying to send the transmission over and over again. The sending system simply sends the data to RabbitMQ and then moves on (fire and forget). In this way, RabbitMQ makes it so that data tranmission is asynchronous.

 

Before we get into how a message gets from the producer to the consumer, the first step is for the sending system to make a connection to RabbitMQ. RabbitMQ will need to be configured with a user, a virtual host, and an AMQP port.

Here is an example of how to make a connection to RabbitMQ in a Java application.

Next you'll probably want to put a messages on a queue, thus you'll need to create a queue.

You can the publish a message onto the queue.

Once the message is on the queue, the Consumer should be able to get the message from the queue.

 

The issue with the above scenario is there is no way for a producer to put a message onto the queue, because a producer will put a message onto what is known as a Exchange. For this reason, for a message to transmit from a producer to a consumer, you will need to:

 

Let's say you have one exchange, but you want certain messages to go to queue "A" and certain messages to go to queue "B". The exchange can be setup with routing keys to route certain messages to certain queues.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 87b86 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |