Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement amqp Protocol Analysis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to achieve amqp protocol analysis, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.

AMQP protocol blog category:

Other

Network Protocol Exchange Application Server Network Application algorithm

At present, asynchronous message model is widely used in various applications, which leads to a large number of message middleware products and protocols. The inconsistency of standards makes the coupling between applications and middleware limit the choice of products and increase the maintenance cost. AMQP is an application layer standard protocol that provides unified messaging services. The client and message middleware based on this protocol can transmit messages, and are not limited by different client / middleware products, different development languages and other conditions.

Of course, this decoupling mechanism is based on protocols that are independent of upper products and languages. AMQP protocol is a binary protocol, which provides asynchronous, secure and efficient interaction between client applications and message middleware. On the whole, the AMQP protocol can be divided into three layers:

This hierarchical architecture is similar to the OSI network protocol and can replace the implementation of each layer without affecting interaction with other layers. AMQP defines an appropriate server-side domain model to regulate the behavior of the server (the AMQP server side can be called broker). Here the Model layer determines the behavior generated by these basic domain models, which is represented by "command" in AMQP and will be analyzed later. The Session layer defines the communication between the client and the broker (both sides of the communication are a peer, which can be called partner), which provides a guarantee for the reliable transmission of the command. The Transport layer focuses on data transmission and maintains interaction with Session, accepts the data from the upper layer, assembles it into a binary stream, transmits it to receiver, then parses the data, and delivers it to the Session layer. The Session layer needs the Transport layer to report network anomalies and transmit command sequentially.

The above is a general description of the AMQP protocol. Below, we will understand the domain model provided by AMQP in terms of our requirements for message services.

The main functions of message middleware are message Routing and Buffering. Two domain models that provide similar functionality in AMQP: Exchange and Message queue.

Exchange receives messages sent by message producers (Message Producer) and sends them to Message queue according to different routing algorithms. Message queue caches messages when they cannot be consumed normally, and the specific caching strategy is determined by the implementer. When the connection between message queue and message consumer (Message consumer) is smooth, Message queue has the responsibility to forward the message to consumer.

Message is the basic unit manipulated in the current model. It is generated by Producer and consumed by Consumer through Broker. Its basic structure has two parts: Header and Body. Header is a collection of attributes added by Producer that control whether the Message can be cached, which queue is received, what priority is, and so on. Body is the data that really needs to be transmitted. It is a binary data stream that is invisible to Broker and should not be affected during transmission.

There will be multiple Message queue,Exchange in a broker. How do you know which Message queue it is going to send the message to? This is the role of Binding shown in the figure above. The creation of the Message queue is controlled by the client application, and after creating the Message queue, you need to determine which Exchange route to receive and save. Binding is the domain model used to associate Exchange with Message queue. Client application controls that Exchange is associated with a particular Message queue and binds to Exchange the condition of which message the queue accepts, also known as Binding key or Criteria.

After being associated with multiple Message queue, there is a routing table in the Exchange that stores the constraints of the messages required by each Message queue. Exchange examines the Header and Body information of each Message it receives to determine which queue to route the Message to. There should be an attribute in Message's Header called Routing Key, which is generated by the Message sender and provided to Exchange routing the Message standard. Exchange has Exchange Type according to different routing algorithms. For example, if Direct is similar, it requires that Binding key is equal to Routing key;, and there is also a schema relationship between Binding key and Routing key; it is also judged by some of the attributes contained in Message. Some basic routing algorithms are provided by AMQP, and client application can also customize various of its own extended routing algorithms.

Here is a new term to introduce: Virtual Host. A Virtual Host can hold some Exchange and Message queue. It is a virtual concept, and an Virtual Host can be a server or a cluster of multiple servers. Under synchronous expansion, Exchange and Message queue can also be deployed on one or more servers.

The producers and consumers of Message may be the same application. The whole AMQP defines the interaction between Client application and Broker. After a rough introduction to AMQP's domain model, you can take a look at how Client connects to Broker.

In AMQP, if Client application wants to communicate with Broker, it needs to establish a connection with Broker. This connection is actually associated with Virtual Host, that is, connection is established between client and Virtual Host. You can run multiple channel concurrently on a connection, and each channel performs communication with the Broker, and the session we provided earlier is attached to the channel.

There are many definitions of Session here, which can not only represent the command distribution mechanism provided within AMQP, but also can be said to be an interface that is macroscopically different from the domain model. Normal understanding is what we usually call interactive context, the main function is to reliably transmit each command on the network. In the design of AMQP, various designs of TCP should be used for reference to ensure this kind of reliability.

In the Session layer, a unique identifier (which can be a UUID) is assigned to each command that the upper layer needs to interact with, so that the command can be checked and retransmitted during transmission. The Command sender also needs to record each command sent to the Replay Buffer in order to get feedback from the receiver to ensure that the command is explicitly received by the receiver or that the command has been executed. For the command that times out and does not receive feedback, the sender retransmits it again. If the receiver has explicitly returned the message and wants to inform the command sender, but the message is lost halfway or the sender does not receive it in other problems, then the sender's continuous retransmission will have an impact on the receiver. In order to reduce this impact, the command receiver sets a filter Idempotency Barrier to intercept those command that have been received.

On how to achieve amqp protocol analysis is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report