What is RabbitMQ?
RabbitMQ is an open-source message broker software. It accepts messages from producers and delivers them to consumers. It acts like a middleman which can be used to reduce loads and delivery times taken by web application servers.
RabbitMQ support multiple protocols, here is the protocol that RabbitMQ support:
AMQP — is the core protocol for RabbitMQ. It’s a Message Broker. But it also supports STORM, MQTT and HTTP through the use of plugins.
HTTP — you’re probably familiar with this one. This is the Hypertext Transfer Protocol. It is not a messaging protocol, but management plugins in RabbitMQ use HTTP to send and receive messages.
STOMP — a simple text-based messaging protocol
MQTT — is a binary protocol known for its lightweight messaging.
RabbitMQ comes with four useful exchange types that cover most of the use-cases for messaging.
- Direct exchange — This will deliver the incoming message to any queue which is binding key exactly matches the routing key of the message. If you bind the queues with the queue name as routing keys, then you can think about it as a one-to-one message delivery. It is simple to deliver the same message to multiple queues by using the binding keys for multiple queues.
- Topic exchange- — This will deliver the incoming message to any queue whose wild card binding key matches the routing key of the published message. Binding keys can contain wild-card matching criteria for a compound routing key. This enables us to write simple services where the logic is well contained,
- Fanout exchange — Some messages need to be delivered to all queues, this is where a fanout exchange can be used instead of writing an elaborate multicast logic in the application. With a RabbitMQ fanout exchange, each service binds the appropriate queue to the exchange without need to specify a binding key, and it all happens automatically. If a binding key is specified, the fanout exchange will simply ignore it and still route/broadcast messages to all queues bound to it.
- Headers exchange — This exchange leverages the structure of AMQP messages and is capable of complex routing based on the headers (including custom ones) of the AMQP message. Headers are metadata attached to each message sent via AMQP.
The message flow in RabbitMQ
There are three AMQP entities in RabbitMQ:
· Exchange
· Binding
· Queues
Requirement- — Print a sample message using RabbitMQ.
Sender Program
Receiver Program
After Run Sender Program
URL to open RabbitMQ — http://localhost:15672/
After Run Receiver Program
Thank You! …..