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

What are the main points of RabbitMQ interview?

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

Share

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

This article mainly shows you "what are the main points of RabbitMQ interview". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "what are the main points of RabbitMQ interview".

1. How do I ensure that messages are sent to RabbitMQ correctly?

RabbitMQ uses sender acknowledgement mode to ensure that messages are sent correctly to RabbitMQ.

Sender acknowledgement mode: if the channel is set to confirm mode (sender acknowledgement mode), all messages posted on the channel will be assigned a unique ID. Once the message is delivered to the destination queue, or after the message is written to disk (a persistent message), the channel sends an acknowledgement to the producer (including the message's unique ID). If an internal error occurs in RabbitMQ and the message is lost, a nack (not acknowledged) message is sent.

The sender acknowledgement mode is asynchronous, and the producer application can continue to send messages while waiting for confirmation. When the confirmation message arrives at the producer application, the callback method of the producer application is triggered to process the confirmation message.

two。 How do I ensure that the message recipient consumes the message?

Receiver message acknowledgement mechanism: consumers must acknowledge each message after receiving it (message reception and message acknowledgement are two different operations). Only when the consumer acknowledges the message can RabbitMQ safely remove the message from the queue.

The timeout mechanism is not used here, and RabbitMQ simply confirms whether the message needs to be resent by breaking the connection to the Consumer. That is, as long as the connection is not broken, RabbitMQ gives Consumer enough time to process the message.

Here are a few special cases:

If the consumer receives the message, disconnects or unsubscribes before confirmation, RabbitMQ assumes that the message has not been distributed and then redistributes it to the consumer of the next subscription.

(there may be a hidden danger of repeated consumption of messages, which needs to be removed according to bizId)

If the consumer receives a message but does not acknowledge the message and the connection is not disconnected, RabbitMQ believes that the consumer is busy and will not distribute more messages to the consumer.

3. How to avoid repeated delivery or consumption of messages?

During message production, MQ generates an inner-msg-id for messages sent by each producer as a basis for de-duplication and idempotence (message delivery fails and is retransmitted) to prevent duplicate messages from entering the queue In message consumption, it is required that there must be a bizId in the message body (globally unique for the same business, such as payment ID, order ID, post ID, etc.) as a basis for de-duplication and idempotence, so as to avoid repeated consumption of the same message.

4. What transmission is the message based on?

Because the creation and destruction of TCP connections are expensive, and the number of concurrency is limited by system resources, it will cause performance bottleneck. RabbitMQ uses channels to transmit data. Channels are virtual connections established within real TCP connections, and there is no limit to the number of channels on each TCP connection.

5. How is the message distributed?

If the queue has at least one consumer subscription, the message will be sent to the consumer in a round-robin. Each message is distributed to only one subscribed consumer (as long as the consumer can process the message normally and confirm it).

6. How is the message routed?

Conceptually, message routing must have three parts: switch, routing, and binding. The producer publishes the message to the switch; the binding determines how the message is routed from the router to a specific queue; the message eventually arrives in the queue and is received by the consumer.

When a message is published to the switch, the message will have a routing key (routing key), which is set when the message is created.

Through the queue routing key, you can bind the queue to the switch.

After the message arrives at the switch, RabbitMQ matches the routing key of the message with the routing key of the queue (there are different routing rules for different switches).

If it can be matched to the queue, the message will be delivered to the corresponding queue.

If it cannot be matched to any queue, the message will enter the "black hole".

The commonly used switches are divided into the following three types:

Direct:

If the routing keys match exactly, the message is delivered to the appropriate queue

Fanout:

If the switch receives a message, it will be broadcast to all bound queues

Topic:

Messages from different sources can reach the same queue.

When using topic switches, you can use wildcards, such as:

"*" any text that matches a specific location, "." Divide the routing key into several parts, "#" matches all rules, etc.

Pay special attention to:

Messages sent to topic switches cannot be arbitrarily set to the routing_key, but must be made by "." Consists of a separated series of identifiers.

7. How do I ensure that messages are not lost?

The premise of message persistence is that the durable property of the switch / queue is set to true, indicating that the switch / queue is a persistent switch / queue, and there is no need to recreate the switch / queue after the server crashes or restarts (the switch / queue will be created automatically).

If a message wants to recover from a Rabbit crash, the message must:

Before the message is released, mark the message as persistent by setting its delivery Mode option to 2 (persistent).

Send a message to a persistent switch

Message arrives in persistent queue

RabbitMQ ensures that persistent messages recover from a server restart by writing them to a persistent log file on disk, and when a persistent message is published to a persistent switch, Rabbit sends a response after the message is submitted to the log file (if the message is routed to a non-persistent queue, it is automatically removed from the persistent log). Once the consumer consumes a persistent message from the persistent queue, RabbitMQ marks the message in the persistence log as waiting for garbage collection. If RabbitMQ restarts the persistent message before it is consumed, Rabbit automatically rebuilds the switch and queue (and bindings) and replays the message in the persistent log file to the appropriate queue or switch.

8. What are the benefits of using RabbitMQ?

Application decoupling (system split)

Asynchronous processing (asynchronously send SMS, push message, log record, etc.) after the reservation registration business is processed successfully

Message distribution

Flow peaking

Message buffering

.

9. Other

RabbitMQ is a message delivery service that acts as a router between the application and the server, while the application or server can send and receive packages. Its communication mode is a "fire-and-forget" one-way way.

The message consists of two parts: the payload (payload) and the label (label).

The payload is the data that needs to be transmitted and can be anything.

The tag describes the payload, and RabbitMQ sends the message to the interested recipient based on the description of the tag.

The above is all the contents of the article "what are the main points of RabbitMQ interview". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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