RabbitMQ
Last updated
Last updated
RabbitMQ is a message-queuing software that can be known as a message carrier or a queue manager. Simply put, it is a piece of software where queues are defined, serving the application with the purpose of transporting one or more messages.
So, why do we need RabbitMQ? Imagine, you currently have a web service that must receive many, many requests per second, but must ensure that not a single request is lost. And your web service is always ready to receive new requests instead of being locked because it is processing the previous request. So the idea here is to put them in a queue between the web service and the processing service. This will ensure that the two processes will be completely separate. In addition, the queue will store requests, without missing any requests when their number becomes extremely large.
Producer/Publisher : Application that sends messages.
Consumer : Application that receives messages.
Queue : Stores messages.
Message : Information transmitted from Producer to Consumer via RabbitMQ.
Connection : A TCP connection between the application and the RabbitMQ broker.
Channel : A virtual connection within a Connection. Publishing or consuming from a queue is done on the channel.
Exchange : Is the place that receives published messages from Producer and pushes them into the queue based on the rules of each type of Exchange. To receive messages, the queue must be located in at least 1 Exchange.
Binding : Takes on the task of linking between Exchange and Queue.
Routing key : A key that Exchange relies on to decide how to route messages to the queue. To put it simply, the Routing key is the address for the message.
AMQP : Advance Message Queuing Protocol, is a message transfer protocol in RabbitMQ.
User : To be able to access RabbitMQ, we must have a username and password. In RabbitMQ, each user is assigned with certain permissions. Users can be assigned special rights to a certain Vhost.
Virtual host/Vhost : Provides separate ways for applications to share a RabbitMQ instance. Different users can have different permissions for different vhosts. Queue and Exchange can be created, so they only exist in one vhost.
There are 4 types of exchange in RabbitMQ. RabbitMQ use Direct Exchange as default behaviour.
Direct Exchange: A Direct Exchange delivers the messages to the queue based on routing key. You can give the queue name to the routing key of exchange. A queue binds to the exchange with a routing key.
Fanout Exchange: In this exchange type, the message is sent to all queues bind to the exchange. Routing key is ignored. If you want to send the published message to all queues ideal way is using the Fanout Exchange.
Topic Exchange: Allowing us to send messages according to the subject. Topic exchange sends the messages based on routing key and routing key patterns.
Header Exchange: This exchange type delivers the messages to queues using headers instead of routing key. In the binding between exchange and queue, a specific argument termed “x-match” indicates whether all headers must match or only one. If “x-match” key’s value is “all” that means is all header values must match. If value of “x-match” key is “any” it means that one header value is enough to match.
Producer sends a Message to an Exchange.
Exchange uses Routing Key and Binding to route Messages to Queue.
Consumer receives Message from Queue.