Introduction to RabbitMQ Basic Concepts

RabbitMQ Concept Diagram

RabbitMQ Concept Diagram

Concept Explanation

Message

A message consists of a message header (i.e., additional configuration information) and a message body (i.e., the message content).

Publisher

The producer of the message, which is a client application that publishes messages to an exchange.

Exchange

An exchange is used to receive messages sent by producers and route these messages to queues in the server.

There are four types of exchanges:

  • Direct type: Compares the routing key in the message with the routing keys associated with all bindings of the exchange. If they match, the message is sent to the corresponding queue of that binding.

  • Topic type: Compares the routing key in the message with the routing keys associated with all bindings of the exchange. If there is a match, the message is sent to the corresponding queue of that binding.

  • Fanout type: Directly forwards messages to the corresponding queues of all bindings, ignoring the routing key during routing.

  • Headers type: Matches the headers in the message with the parameters associated with all bindings of the exchange. If there is a match, the message is sent to the corresponding queue of that binding (less commonly used, similar to the Direct type).

Note: Detailed explanations of the exchange types will be provided in the following sections on working modes. This is just an overview.

Binding

The relationship used to establish a connection between message queues and exchanges.

Queue

A message queue used to store messages until they are delivered to consumers. It serves as both a container for messages and the endpoint for messages. A message can be delivered to one or more queues. Messages remain in the queue, waiting for consumers to connect and retrieve them.

Connection

A network connection, such as a TCP connection.

Channel

A channel is a virtual connection established within a real TCP connection. All AMQP commands are sent through channels, whether it's publishing messages, subscribing to queues, or receiving messages. This design introduces the concept of channels to reuse a single TCP connection, as establishing and terminating TCP connections is costly for the operating system.

Consumer

The consumer of messages, representing a client application that retrieves messages from message queues.

Virtual Host

A virtual host represents a set of exchanges, message queues, and related objects. It is an independent server domain sharing the same identity authentication and encryption environment. Each vhost is essentially a mini-version of a RabbitMQ server, with its own queues, exchanges, bindings, and permission mechanisms.

Vhosts are a fundamental concept in AMQP and must be specified when establishing a connection. The default vhost for RabbitMQ is /.

Note: Virtual Host is a form of resource isolation strategy that allows for the partitioning of multiple isolated areas within the same RabbitMQ server.

Broker

Represents the physical message queue server entity.