Messaging — The Rabbit Way
RabbitMq: The robust AMQP/MQTT message broker
The AMQP is a proven winner for the enterprise scenarios requiring uncompromised reliability, performance, throughput, and scalability. For example, imagine the strict messaging requirements for financial trading or banking systems, where the delay for a fraction of a micro-second or the loss of data is simply not imaginable.
RabbitMq is an open-source AMQP/MQTT message broker built over Erlang OTP and can support massive messaging for concurrent operations. It is the same Erlang that powers WhatsApp to transport billions of messages every day.
The RabbbitMq acts as a secure message transfer bus, generally over TCP/IP, for distributed and asynchronous systems. The whereabouts of the message are known while it is traveling physically from one system to another.
The AMQP based messaging covers all scenarios in a messaging system, e.g., where
— Response against a message is needed
— Response not required, but the delivery confirmation is needed
— No response and no delivery confirmation is needed
The senders/receivers need not be active during actual communication. It provides a fallback mechanism to retain messages in the queue when the recipients are offline. The retained messages are delivered when the recipient service goes live again — thus enabling fault tolerance.
The fault-tolerant nature of the AMQP is a step ahead of RESTful HTTP web-services that expect the receiver to be alive at the time of the request or the message gets lost. The AMQP also beats HTTP while processing large volumes of data in a relatively shorter time.
A queue can receive messages from multiple publishers. And a publisher can send messages to the various consumers. The messages are stored with the queues and they can be contained in memory or on the physical disk. How long the message stays in the queue, depends on the queue settings.
The message routing is done by the Message — Exchange between the publishers and consumers. The queue name serves as the address of the sender/receiver service. The sender has the Routing Key while the receiver has the Binding Key of the message. The keys hook the queues with the exchange.
Depending upon how the messages need to be received, the exchanges are of four types -
Direct Exchange: The sender knows the recipient’s full queue name and sends the message to that queue.
Topic Exchange: The sender intends to send the message to any queue that matches the name based on a wild card, e.g., company_name.*.queue will match company_name.managers.queue and company_name.executives.queue
Fanout Exchange: The sender intends to send the message to all the bound queues.
Header Exchange: The sender uses AMQP message structure to send the message with additional metadata for -
— Attaching priority, urgency, and expiry information to the messages
— Clustering — combining several rabbitMq brokers for further scaling the system
— Use in Plug-in for additional tasks, e.g., the management, authentication and authorization, back-up solutions, etc.
RabbitMq for IoT: IoT systems can publish and consume messages using RabbitMq as the MQTT broker. It can also serve as a gateway for AMQP services to the IoT devices.