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 interview questions for RabbitMQ?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what are the interview questions about RabbitMQ, the editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

What is RabbitMQ?

A message queuing technology using AMQP advanced message queuing protocol, the most important feature is that the consumer does not need to ensure the existence of the provider, which realizes a high degree of decoupling between services.

Second, why use RabbitMQ?

① has a series of advanced functions such as asynchronous, peak clipping, load balancing and so on in distributed system.

② has a persistence mechanism, and process messages and information in the queue can also be saved.

③ implements decoupling between consumers and producers.

④ for high concurrency scenarios, the use of message queues can make synchronous access into serial access to achieve a certain amount of flow limit, which is conducive to the operation of the database.

⑤ can use message queuing to achieve the effect of asynchronously placing an order. In the queue, the backend logically issues the order.

3. What are the scenarios for using RabbitMQ?

① asynchronous communication across systems, message queuing can be used in all places where asynchronous interaction is needed. Just like we need to send text messages and e-mail (asynchronous) in addition to making phone calls (synchronous).

The coupling between multiple ② applications, because the message is platform-independent and language-independent, and semantically it is no longer a function call, so it is more suitable to be used as a loosely coupled interface between multiple applications. Based on the coupling of message queue, there is no need for the sender and receiver to be online at the same time. In enterprise application integration (EAI), file transfer, shared database, message queuing, and remote procedure calls can all be used as integration methods.

For synchronous variation steps in ③ applications, such as order processing, the front-end application can put the order information into the queue, and the back-end application can get message processing from the queue in turn. A large number of orders during peak periods can be slowly disposed of in the queue. Because synchronization usually means blocking, blocking of a large number of threads can degrade the performance of the computer.

④ message-driven architecture (EDA), the system is divided into message queues, and message makers and message consumers. A processing flow can be divided into multiple stages (Stage) as needed, the phases are connected by queues, the results of the previous phase are put into the queue, and the latter stage gets messages from the queue to continue processing.

⑤ applications need more flexible coupling, such as publish and subscribe, and can specify routing rules.

⑥ cross-LAN, and even cross-city communications (CDN industry), such as Beijing computer room and Guangzhou computer room application communication.

4. What are the important roles of RabbitMQ?

The important roles in RabbitMQ are: producers, consumers, and agents:

① producer: the creator of the message, responsible for creating and pushing data to the message server

② consumer: the recipient of the message, used to process the data and acknowledge the message

③ agent: it is RabbitMQ itself, which is used to play the role of "express delivery". It does not produce messages, but only plays the role of "express delivery".

5. How to ensure that messages are sent to RabbitMQ correctly? How do I ensure that the message recipient consumes the message?

1. Sender confirmation mode

If ① sets the channel 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).

③ sends a nack (notacknowledged, unacknowledged) message if an internal error occurs in RabbitMQ, resulting in the loss of the message.

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.

2. Receiver confirmation mechanism

The ① consumer 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.

② does not use the timeout mechanism here, and RabbitMQ only confirms whether the message needs to be resent through the disconnection of the Consumer. That is, as long as the connection is not broken, RabbitMQ gives Consumer enough time to process the message. Ensure the final consistency of the data.

3. Several special cases are listed below.

① if the consumer receives the message and disconnects or unsubscribes before confirming, RabbitMQ will assume that the message has not been distributed and then redistribute it to the consumer of the next subscription. (there may be a hidden danger of repeated consumption of messages, which needs to be removed.)

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

6. How can RabbitMQ avoid losing messages?

① message persistence

② ACK confirmation mechanism

③ sets cluster mirroring mode

④ message compensation mechanism.

What are the conditions to ensure the success of message persistence?

① declares that the queue must be set persistent durable to true.

The ② message push delivery mode must be set to persistence and deliveryMode to 2 (persistent).

The ③ message has arrived at the persistence switch.

The ④ message has reached the persistence queue.

The above four conditions are met to ensure the success of message persistence.

What are the disadvantages of RabbitMQ persistence?

The lack of persistence is to reduce the throughput of the server because the disk is used instead of memory storage, thus reducing the throughput. Ssd hard drives can be used as much as possible to alleviate throughput problems.

9. How many types of broadcasts does RabbitMQ have?

Three broadcast modes:

① fanout: all queue from bind to this exchange can receive messages (broadcast only, recipients bound to RabbitMQ can receive messages)

② direct: the only queue determined by routingKey and exchange can receive messages

③ topic: the queue of all routingKey bind that conform to routingKey (which can be an expression at this time) can receive messages

What is the function of vhost in RabbitMQ?

Vhost can be understood as virtual broker, that is, mini-RabbitMQ server. It contains independent queue, exchange and binding, etc., but the most important thing is that it has an independent authority system, which can be controlled by vhost users. Of course, from a global point of view of RabbitMQ, vhost can be used as a means of isolating different permissions (a typical example is that different applications can run in different vhost).

This is the end of the article on "what are the interview questions for RabbitMQ". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please 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

Development

Wechat

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

12
Report