What you need to know about RabbitMQ, the most used messaging system on the market. This widely used system has become one of the most requested messaging applications on the market.
However, do you know what a messaging system is? How does it work? Is there more than one type of architecture that defines the flow of messages within the system?
Tutorial RabbitMQ:
Lesson 01: RabbitMQ #1 – Messaging Systems
Lesson 02: RabbitMQ #2 – RabbitMQ in docker-compose
Lesson 03: RabbitMQ DLX with Java Spring
Also, which programming languages support RabbitMQ. This article describes the theory behind RabbitMQ. In future articles we will apply the knowledge when creating a scenario using the API java spring-rabbitmq.
What is a messaging system?
This concept of messenger is based on the matter of distributed systems within computing. It is characterized by message-oriented communication, which can be classified as persistent or transient.
Thus, messaging systems can be clustered, have scalability, are fault tolerant, with asynchronous communication. Furthermore, it is intuitive to say that it operates as a distributed system.
Distributed systems Definition
A distributed system operates with its components locally dispersed. Consequently, there is an alignment between the components. In this way, in communication, devices coordinate their actions together. However, the user perceives the system (ex: RabbitMQ) as a single service provider component.
Message-oriented communication
In content-oriented communication systems we have the concept of middleware services, generally known as message queuing system. Still, the middleware also has the MOM nomenclature – Message-Oriented Middleware.
There are a few different ways of implementing message-oriented systems. However, the queuing system provides extensive support for asynchronous persistent communications. Consequently, the system is more suitable for scenarios with variation in the status of the parties involved.
Okay… so how does this asynchronous communication occur? The messaging system intermediates the sending and receiving of requests. In this way, the parties involved do not need to be operational at the same time. In this case, we have a system that tolerates minutes instead of seconds or milliseconds.
Message flow architecture
The architecture that determines the flow of communication between the parties are classified as: e publisher/subscriber queuing system. Each architecture has an intermediation scheme. However, both scenarios use queue abstraction. The basic idea of the operation of a queue is the FIFO – First In First Out system.
The main idea of this system is to establish connections between the parties involved. In this way, the system is responsible for routing and storing messages. Consequently, user applications communicate transparently.
Messages transferred within the queues are routed according to some criteria. The message control flow defines the type of routing that will be applied to messages. Consequently, message flow depends on the system architecture. In addition, there is even message storage.
Routing consists of analyzing from previously established criteria to whom the message will be delivered. In turn, message storage occurs in the queue that connects the system to the destination. If the application that will consume the content is offline (for whatever reason), the message will be stored until requested.
Communication protocols
Communication protocols are responsible for operating the system. Consequently, the model defines the protocol’s main operating guidelines. However, the application can still define other features in addition to those covered in the model.
Our focus will be on the AMQP communication protocol in its version 0.9.1. Despite appearing contradictory, version 1.0 of AMQP implements another communication model. As such, version 1.0 is not the evolution of the protocol.
There are other communication protocols such as HTTP, STOMP, and AMQP 1.0 itself. Each of them implements a different communication model. Thus, it is up to the computer professional to verify which one will meet their needs.
Within this context, one of the most used applications currently in messaging systems is the RabbitMQ. Thus, its base is in the AMQ model and its operation in the AMQP 0.9.1 protocol.
When does this type of system become interesting?
The operating mode of a traditional system requires synchronous communication, that is, the receiving side must be running at the same time as the request is sent. This way, if the end of the communication that will receive the message is offline, the package will not be delivered.
An example of this scenario is found precisely in the establishment of TCP communication. Thus, for a TCP connection to be established, the parties must realizardohandsake before sending packets.
Still talking about TCP … we can describe two scenarios. In the first one, the client sends several connection initiation packets. However, it will not respond due to server failure. Unlike the first, the second scenario that can cause the connection failure.
Suppose several clients making requests at the same time. There will be a huge flow of packets that can cause different problems, such as: server slowdown, performance drop, request response delay, and finally server crash.
In a messaging system, communication is not compromised if a destination node fails. The system is responsible for managing messages until they are delivered to their respective recipients.
The reader may then appreciate that there are scenarios in which this alternative communication is necessary. Therefore, message-oriented systems are a viable solution.
AMQP Protocol
AMQP 0-9-1 is a binary messaging protocol, ie where there are two parties involved. Thus, the two ends of communication are called producers and consumers. Messages received by consumers are sent by producers.
Another nomenclature is that of publisher (publisher) and subscriber (subscriber). This in turn is only associated with the Pub/Sub model. However, the first nomenclature can be used in queuing and Pub/Sub systems. We will deal with this topic in the future in another article.
Continuing… AMQP is thus binary, and a semantic framework for microservices, and enterprise messaging. It defines how messages will flow within the asynchronous communication system. As well as the function of system components.
“Semantics: in a linguistic system, the component of the meaning of words and the interpretation of sentences and utterances.”
oxford language
What then would a semantic framework be?
The concept of semantics is linked to the meaning of words. Consequently, we can extrapolate to our context as the meaning, or role of a component within the system. In this way, AMQP defines the structure and components of the system.
Each component has its order within the communication structure. Let’s use RabbitMQ for example. A producer communicates with the message-broker by sending the messages. In turn, a consumer establishes communication through queues.
Permissions, limits, role within the system and which features each component can modify are defined by the protocol.
AMQP 0.9.1 version
As I mentioned earlier, despite similar names, AMQP 0-9-1 and AMQP 1.0 are completely different protocols. Therefore, AMQP 1.0 has a different scope and topology model than version 0.9.1. RabbitMQ, the focus of our article, operates on the basis of AMQP 0-9-1. However, it provides support via plugins to the AMQP 1.0, MQTT and STOMP communication protocols.
AMQP performs interoperability between clients and servers of the type messaging middleware servers (brokers). The purpose of the protocol is to allow industry and developers to adopt standardization regarding middleware messaging technology. Thus, lowering enterprise and systems integration costs, and providing industry-level service integration to a wider audience.
Interoperability
To ensure system interoperability, network protocols and semantics must be specified in server-side services. AMQP implements the protocols by defining a set of messaging resources, and a protocol called network wire-level.
The foundation of the AMQP protocol is based on a defined set of messaging features called “Advanced Message Queuing Model” (AMQ model). The AMQ model consists of a set of components that route and store messages within the broker service. In addition, there is even a set of rules for connecting these components. A wire-level network protocol, AMQP, that allows client applications to talk to the server and interact with the AMQ model it implements.
RabbitMQ – Overview
RabbitMQ is an open source message-broker application for communicating and exchanging messages between parties. As it was developed in erlang, it is very light and efficient. The erlang language was developed by Ericson, with a focus on distributed systems.
Furthermore, unlike traditional systems, RabbitMQ operates by establishing asynchronous communications. Consequently, the parties involved do not need to be operational at the same time for communication to take place.
RabbitMQ is an application of the AMQP protocol in version 0.9.1. In this case, the production (messaging) server will be connected to an exchange, instead of being connected to the queue directly.
The exchange is similar to a mail that directs messages according to their address.
There are other messaging applications on the market. However, and what defines each of them is related to the flow of messages within the system. In other words, the way the message moves through the system.
RabbitMQ Features
In RabbitMQ, this information is part of the metadata. Thus, the developer has a lot of control over how the message moves through the system rather than the broker administrator.
Outro benefício do RabbitMQ é ser cloud friendly. Podendo ser implementado em ambientes como AWS. Ainda assim, pode ser implementado no docker ou outro sistema de containers.
Also, RabbitMQ can be clustered. As it is a distributed system application, there are several benefits, such as: full tolerance, high available, high throughput and clustering.
RabbitMQ still has cross-language communication. This means that the message can be consumed by a JavaScript or python server. Therefore, the operation of RabbitMQ is independent of the application language.
A producer can have their application in a different language than the consumer’s application, yet the system remains operational.
Another attractive feature of RabbitMQ is security. It supports security protocols such as SSL, TLS (3rd version of SSL), authentication and authorization protocols such as LDAP.
Tutorial RabbitMQ:
Lesson 01: RabbitMQ #1 – Messaging Systems
Lesson 02: RabbitMQ #2 – RabbitMQ in docker-compose
Lesson 03: RabbitMQ DLX with Java Spring
Bibliographic references
AMQP communication protocol specification
Tanenbaum, Andrew S., and Steen V. Maarten. “Distributed Systems: Principles and Paradigms” Pearson – 2° edição.
Simplificando Redes on the social media