RabbitMQ - Technological watch

Learn what is RabbitMQ in less than 5 minutes !
Friday, February 16, 2024

Introduction

In the field of DevOps technologies, RabbitMQ stands out as a versatile and powerful tool for managing messaging within distributed systems. Developed as an open-source solution, RabbitMQ was crafted in Erlang by Ericsson, offering robustness and reliability.

At its core, RabbitMQ functions as a message broker (akin to Kafka), facilitating communication between producers and consumers through queues. Employing a FIFO (First In, First Out) approach, messages are sequentially processed, ensuring orderly delivery from producer to consumer.

Loading graph...

First introduced in 2007 by Rabbit Technologies Ltd, RabbitMQ underwent ownership changes, ultimately falling under the purview of SpringSource (VMware) in 2010, later integrated into Pivotal Software.

One of RabbitMQ’s key strengths lies in its support for asynchronous messaging and cluster mode, enabling seamless scalability and fault tolerance within distributed systems. Moreover, it boasts extensive library support across multiple programming languages, including Java, PHP, Python, and Go, enhancing its interoperability and ease of integration.

Primarily utilized within microservices architectures, RabbitMQ serves as a communication backbone, facilitating smooth interactions between disparate services. Its inherent design promotes easy maintenance and scalability, allowing organizations to manage growing workloads and mitigate potential failures effectively.

Usage examples

RabbitMQ offers the flexibility to store various object types, making it a versatile choice for diverse messaging needs:

  • SMS and Email: Facilitate communication by storing messages for delivery through different channels.
  • Instructions: Transmit commands or directives for remote execution or processing.
  • Command Lines: Exchange command-line instructions between systems or services.
  • Images to Run: Store images or containers to be executed within a distributed environment.
  • Jobs: Queue up tasks or jobs for asynchronous processing, ensuring efficient resource utilization.

Protocols

RabbitMQ supports multiple protocols to facilitate seamless communication across various systems and devices:

  • AMQP (Advanced Message Queuing Protocol): A robust and widely adopted protocol for message-oriented middleware, with implementations available in various languages such as C and Python.
  • STOMP (Streaming Text Oriented Message Protocol): Designed for simplicity and interoperability, STOMP operates over TCP, enabling straightforward communication between clients and message brokers.
  • MQTT (Message Queuing Telemetry Transport): An efficient and lightweight protocol ideal for publish/subscribe messaging, commonly used in IoT (Internet of Things) applications due to its low bandwidth requirements and support for intermittent connectivity.
  • HTTP (Hypertext Transfer Protocol): Leveraging HTTP, RabbitMQ provides a web-based interface for communication, allowing for easy integration with existing web technologies and services.

Additionally, RabbitMQ supports secure communication through encryption using protocols such as AMQPS (AMQP over TLS/SSL) and MQTTS (MQTT over TLS/SSL), ensuring data confidentiality and integrity in transit.

Plugins

RabbitMQ offers a range of plugins to extend its functionality and tailor it to specific requirements:

  • rabbitmq_management_agent: Provides an HTTP-based API and web interface for monitoring and managing RabbitMQ server instances.
  • rabbitmq_shovel: Facilitates data transfer between RabbitMQ broker instances or between RabbitMQ and other messaging systems.
  • rabbitmq_federation: Enables the exchange of messages between RabbitMQ brokers in a federated manner, enhancing scalability and fault tolerance.
  • rabbitmq_prometheus: Integrates RabbitMQ metrics with Prometheus monitoring, allowing for comprehensive performance analysis and alerting.
  • rabbitmq_priority_queue: Prioritizes messages within queues based on specified criteria, ensuring critical tasks are processed promptly.
  • rabbitmq_email: Sends email notifications based on predefined events or conditions within RabbitMQ, enhancing operational visibility and alerting capabilities.

Definitions

Outside the Broker

To understand RabbitMQ effectively, it’s essential to grasp the following terms:

  • Producer: Entities responsible for creating and formatting messages, establishing connections to the broker, and dispatching messages. Producers often utilize user credentials for authentication.
  • Broker: The RabbitMQ server, serving as the central hub for message exchange. Brokers host queues, manage associations within a cluster, and enforce security measures such as user and virtual host (vhost) management.
  • Consumer: Entities that subscribe to queues and consume messages for processing or other actions.
  • Message: Units of data transmitted through RabbitMQ, characterized by various types, headers, metadata, and an inherent order. Messages may be replicated based on configuration requirements.

Roles within RabbitMQ typically follow the sequence: Producer > Broker > Consumer.

Inside the Broker

Exploring the internal components of RabbitMQ:

  • Channel: A mechanism for multiplexing connections within RabbitMQ. Channels are elements of connections and facilitate efficient message transmission. In code, channels are created within connections and used for actions such as message publishing.
channel, err := connection.Channel()
err = channel.Publish(...)
  • Exchanges: Components responsible for receiving messages and routing them to appropriate queues based on defined rules. RabbitMQ supports various exchange types, including direct, fanout, topic, and headers.
  • Binding: Links established between exchanges and queues, defining the routing logic for message delivery.
  • Routing Key: A parameter utilized during message routing, determining which queues should receive specific messages based on matching criteria.
  • Queue: Storage units within RabbitMQ for holding messages until they are consumed. Queues come in different types such as classic, quorum, or stream, offering various durability features.
  • VHost: Virtual hosts within RabbitMQ, serving to separate and isolate resources and configurations, whether on a single broker or across multiple brokers.

Schema

Here is a simplified schema of RabbitMQ:

Loading graph...

Thus, the flow within RabbitMQ unfolds as: Producer > Channel > Exchange > Binding > Routing Key > Queue > Consumer.


Recommended articles