AMQP protocol: the interaction process between consumers, producers and RibbitMQ nodes, the core component of RibbitMQ

Original link
1. What is the AMQP protocol?
AMQP full name: Advanced Message Queuing Protocol (Advanced Message Queuing Protocol). It is a development standard of application layer protocol, designed for message-oriented middleware.
The client and message middleware based on this protocol can transmit messages without being restricted by different products and development languages ​​of the client/middleware. The bottom layer is developed by Erlang (Ai Leng) language, and typical supporters include RabbitMQ and ActiveMQ.
2. AMQP producer transfer process
insert image description here
1. The producer establishes a connection with the Broker (node) and follows a certain protocol;
the producer packs information such as ip, port, user name, password, etc. in the Protocol Header (protocol header), and sends to the Broker ( Node) initiates a connection request, the two establish a connection
2, open a channel (channel)
3, send a message
4, release resources

Interview question: Why does RibbitMQ process messages based on channels (channels) instead of processing messages based on connections?
An application has multiple threads that need to consume or produce messages from rabbitmq, so many connections, that is, multiple tcp connections, will inevitably be established. For the operating system, establishing and destroying tcp connections is very expensive . If When encountering usage peaks, performance bottlenecks will also appear. Rabbitmq adopts a method similar to nio to multiplex tcp connections, which can not only reduce performance overhead, but also facilitate management.
Each thread holds a channel, so the channel multiplexes TCP connections.
In a connection (connection), there are multiple channels (channels)

3. AMQP consumer circulation process
insert image description here
1. Similar to producer, establish connection
2. Open channel
3. Receive message
4. Push message
5. Send confirmation
There are two types of consumer confirmation: automatic confirmation and manual confirmation
Reference link
Here is a "reliable consumption" problem:
automatic consumption : when the broker sends a message to the consumer, if the "send and finish" method is used, the TCP connection has been broken before the consumer has received the message, so The consumer has not received the message, but the Broker node (that is, the RibbitMQ server) thinks that the consumer has already consumed; this is considered an unsafe
manual consumption : (Basic Ack) enables manual reply to Ack, and the server waits for the consumer to reply to confirm the consumption 6. Release
resources

The core components of RabbitMQ

The core components of RabbitMQ

Guess you like

Origin blog.csdn.net/dayuiicghaid/article/details/128450281