Introduction to the AMQP protocol
AMQP (Advanced Message Queuing Protocol) is an application-layer standard protocol that provides unified messaging services, and is an open standard for application-layer protocols designed for message-oriented middleware. AMQP is a network protocol for passing asynchronous messages between processes.
Clients and message middleware based on this protocol can deliver messages without being restricted by different client/middleware products, different development languages, etc.
The main characteristics of AMQP are message-oriented, queued, routing (including peer-to-peer and publish/subscribe), reliability, and security. AMQP enforces the behavior of message providers and clients, enabling true interoperability between different vendors.
Routing messages
In the AMQP architecture, any successful message routing consists of three parts:
- Exchange: Where producers publish messages
- Queues: Where consumers receive messages
- Bindings: How messages are routed from the switch to a specific queue
Exchanges and Bindings
So how does the message reach the queue? Whenever you want to deliver a message to a consumer, you must first send it to the exchanger. Then, based on certain rules or routing keys, RabbitMQ will decide which queue it should deliver messages to.
Rules - or routing keys - enable you to bind a queue to the exchange. RabbitMQ will attempt to match the routing key in the message to the key used in the binding. The message is then delivered to the queue based on one of four exchange types: fanout, topic, direct, header
Fanout Exchange
This type of exchange broadcasts all the messages it receives to all queues bound to it. Any routing keys provided with the published message will be ignored.
Topic Exchange
In this type of exchange, messages are sent to a queue based on the routing key. This means that messages sent to the topic exchange must have a specific routing key, which must be a list of words, separated by points (e.g., 'acs.deviceoperations.'). The wording limit is 255 bytes.
The binding key must be in the same format as the routing key. Therefore, messages sent with a specific routing key will be delivered to each queue bound with a matching binding key.
Binding keys allow the following expression rules:
*(asterisk) can replace only one word # (hash) can replace zero or more words When a queue is bound with a "#" (hash) binding key, it will receive all messages regardless of the routing key, just like in a Fanout fan-out exchange.
Direct Exchange
When a queue is declared, it willAutomatically bind to a switch that uses the queue name as the routing key。 If the routing key matches, the message is delivered to the appropriate queue.
Header Exchange
Header switches are somewhat similar to topic switches, but unlike topic switches, the routing is based on route keys, and the routing values of header switches are based on the header data of the message. The topic switch routing key is only a string, while the header switch can be an integer and a hash.
(End)
|