An introduction to RabbitMQ - What is RabbitMQ?
What problem does RabbitMQ solve?
1) we start the call,
2) wait for the other party to answer,
3) have a nice discussion,
4) hang up the phone.
What is RabbitMQ?RabbitMQ is a free, open-source and extensible message queuing solution. It is a message broker that understands AMQP (Advanced Message Queuing Protocol), but is also able to be used with other popular messaging solutions like MQTT. It is highly available, fault tolerant and scalable. It is implemented in Erlang OTP, a technology tailored for building stabe, reliable, fault tolerant and highly scalable systems which possess native capabilities of handling very large numbers of concurrent operations, such as is the case with RabbitMQ and other systems like WhatsApp, MongooseIM, to mention a few.
To show off the versatility of RabbitMQ, we are going to use three case studies that demonstrate how RabbitMQ is well suited as a black-box managed service approach, as one that integrates tightly with the application enabling a well-functioning micro-service architecture, or as a gateway to other legacy projects.
RabbitMQ as a general message-busWhen a monolith system is broken down to separate subsystems, one of the biggest problems that needs solving is which communication technology to use. A solution like Mulesoft, or MassTransit can “wire” services by declaring HTTP listeners and senders. This kind of solution treats RabbitMQ as a black box, but is still able to leverage the capabilities of RabbitMQ. As an example of direct communication, let’s use HTTP to “connect” the individual services. While it is a well-supported and solid choice, it has some drawbacks:
2) The communication is ephemeral. Messages are prone to being dropped or duplicated on the network layer. If a service is unavailable temporarily, the delivery fails.
RabbitMQ as an advanced routing layer for micro-services
On the other end of the spectrum is an architecture which is more fluid and adapts to the ever-changing needs of many micro-services. What makes RabbitMQ shine in this environment is the very powerful routing capabilities it provides.
1) Direct exchange. This will deliver the incoming message to any queue whose 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.
2) 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. (e.g. the binding key logs.*.error will match the routing keys logs.accounting.error and logs.ui.error ). This enables us to write simple services where the logic is well contained, and the message will arrive to the correct services through the “magic” of RabbitMQ.
3) 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.
4) 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.
1) Custom plug-ins. RabbitMQ is extensible by allowing its users to add plug-ins. Almost every aspect of RabbitMQ is customisable, including the management, authentication and authorisation, back-up solutions, and clustering.
2) Clustering. When a single RabbitMQ server is not enough, multiple RabbitMQ brokers can be connected to work together and scale the system. It can enable RabbitMQ to process more messages or increase resilience to errors.
3) Quality of Service tuning. Time-sensitive message delivery can be helped by attaching a TTL (Time-to-Live) value to either the message or the queue. Timed out messages can be automatically delivered to a Dead-letter queue. Combining ordinary routing logic and these extra features can lead to highly advanced routing logics. Another useful feature is using priority queues where the publisher can assign a priority level to each message. It is also possible to limit the number of unacknowledged messages, which allows for the performance tuning of the consuming services, in this case, RabbitMQ applies a back-pressure mechanism.
RabbitMQ integrated into legacy systems
In the previous use-case, I mentioned the possibility of using plug-ins to extend the functionality of RabbitMQ. This powerful feature allows RabbitMQ to act as a mediation layer between your RabbitMQ native (AMQP capable) services and other legacy applications. Some notable examples include:
1) Using RabbitMQ as an MQTT broker by simply enabling a plug-in. This opens up the landscape to many IoT technologies.
2) RabbitMQ’s JMS (Java Message Service) plug-in, which allows RabbitMQ to communicate with any JMS capable messaging solution.
3) If your application is using a proprietary protocol for communicating, it is possible to develop a custom plugin to connect to any such services.
As the above examples demonstrate, there is hardly anything that RabbitMQ can’t communicate with. But as with
anything in life, it has a price. Although configuring RabbitMQ is mostly straightforward, sometimes the mere number
of features can be overwhelming. If you face any problems with designing, implementing or supporting your
RabbitMQ brokers, reach out to our expert team here. Or, if you’d like to kick start your career in one of the most indemand technologies sign up for our RabbitMQ training course.