AMQP中的架构和组成元素

Advanced Message Queuing Protocol
(AMQP)
AMQP is the abbreviation of Advanced Message Queuing Protocol. AMQP creates
the interoperability between Producer, Message Broker, and Consumer. First of
all, we need to answer this question: Why we need AMQP? Since different types of
message formats and different types of routing formats need to be standardized,
AMQP organization creates a well-defined industry-wide messaging middleware
standard.

因为有太多的类型的消息格式和路由格式需要标准化,所以提出了定义良好的、行业应用广泛的消息中间件标准
As we discussed, AMQP's main responsibility is the interoperability of the systems
inside the messaging systems. Therefore, we need to explain the scope of the AMQP
as explained in the AMQP Specification Document:
• A defined set of messaging capabilities
• A network wire-level protocol

AMQP的主要职责是为消息系统内部提供互操作性,因此,我们需要理解AMQP的范围:定义一套消息的能力,一个网络写入级别的协议

AMQ元素构成

• Message Flow: It explains the message life cycle
• Exchanges: It accepts messages from publisher, and then routes to the
Message Queues
• Message Queues: It stores messages in memory or disk and delivers
messages to the consumers
• Bindings: It specifies the relationship between an exchange and a message
queue that tells how to route messages to the right Message Queues

*消息流,它解释了消息的生命周期;

*交换机,从生产者接收消息,并路由到消息队列;

*消息队列,存储消息在内存或者硬盘,提供消息给消费者

*绑定器,它指定了交换机和队列的关系,用来表明如何路由消息到指定的队列

A Message consists of these following attributes:
• Content that is a binary data
• Header
• Properties
The following screenshot gives the general idea of the AMQP Message:

Virtual hosts
AMQP has a functionality to have multiple isolated environments, which have
groups of users, exchanges, message queues, and so on with the help of Virtual
Hosts. It is really similar to the Virtual Hosts of any Web Server in the enterprise.

Exchange types

The direct exchange type – amq.direct  直连
The flow of direct exchange type (as shown in the following screenshot) is as follows:
1. A message queue binds to the exchange using a routing key, K.
2. Then, a publisher sends the Exchange a message with the routing key, R.
3. The message is passed to the message queue if K equals to R.

The fan-out exchange type – amq.fanout  广播
The flow of direct exchange type(as shown in the previous screenshot) is as follows:
1. A message queue binds to the exchange with no arguments.
2. Whenever a publisher sends the Exchange a message, the message is passed
to the message queues unconditionally:

The topic exchange type – amq.topic 主题  
The flow of direct exchange type (as shown in the previous screenshot) is as follows:
1. A message queue binds to the Exchange using a routing pattern, P.
2. A publisher sends the exchange a message with the routing key, R.
3. The message is passed to the message queue if R matches P.
4. Matching algorithm works as follows: The routing key used for a topic
exchange must consist of zero or more words delimited by dots such as
"news.tech". The routing pattern works like a regular expression such as
"*" matches single word and # matches zero or more words. For instance,
"news.*" matches the "news.tech".

根据routing 匹配

The headers exchange type – amq.match
Headers Exchange Type is the most powerful exchange type in AMQP. Headers
exchange route messages based on the matching message headers. Exchange ignores
the routing key. Whenever creating the exchanges, we specify the related headers
on the exchanges, so message's headers are matched with the exchange headers
using "x-match" argument. We will be looking at this Exchange Type in the Client
Chapters.

根部headers头部匹配

原文地址:https://www.cnblogs.com/PerfectBeauty/p/12632625.html