In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the Java RabbitMQ interview questions". The explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the Java RabbitMQ interview questions"?
What is 1.RabbitMQ?
RabbitMQ is an open source, Erlang-written message middleware based on AMQP (Advanced message queuing Protocol) protocol.
two。 Why use message queuing?
In essence, it is because of the rapid development of the Internet and the continuous expansion of business, which makes the technology architecture need to evolve constantly.
From the previous single architecture to the current micro-service architecture, hundreds of services invoke and depend on each other. It has been a big deal since the early days of the Internet that there were 100 online users on a server, to Wechat, which now has 1 billion daily active users. At this point, we need a "tool" to decouple the relationship between services, control the reasonable use of resources, buffer traffic peaks, and so on. Therefore, message queuing came into being.
It is often used to implement: asynchronous processing, service decoupling, flow control (peaking).
3. Talk about the major components of RabbitMQ
Broker: an application that receives and distributes messages. RabbitMQ Server is Message Broker.
Virtual host: designed for multi-tenancy and security reasons, the basic components of AMQP are divided into a virtual grouping, similar to the concept of namespace in the network. When multiple different users use the services provided by the same RabbitMQ server, multiple vhost can be divided, and each user creates an exchange/queue in their own vhost, and so on.
TCP connection Channel between Connection:publisher/consumer and broker: if a Connection is established every time you visit the RabbitMQ, the overhead of establishing the TCP Connection when the message volume is large will be huge and inefficient. Channel is a logical connection established within connection. If the application supports multithreading, each thread usually creates a separate channel for communication. AMQP method includes channel id to help clients and message broker identify channel, so the channel is completely isolated. L Channel, as a lightweight Connection, greatly reduces the cost of establishing TCP connection by the operating system.
Exchange: message arrives at the first stop of broker, matches the routing key in the query table according to the distribution rules, and distributes the message to queue. The common types are: direct (point-to-point), topic (publish-subscribe) and fanout (multicast).
Queue: the message is finally sent here for consumer to pick up.
Binding: a virtual connection between exchange and queue that can contain routing key,Binding information in a query table in exchange and used as a basis for message distribution.
Producer: the message producer is the party who delivers the message. A message generally consists of two parts: the message body (payload) and the label (Label).
Consumer: consume the message, that is, the party that receives the message. Consumers connect to the RabbitMQ server and subscribe to the queue. When consuming messages, only the message body is consumed and the tags are discarded.
4. What are the advantages and disadvantages of message queuing?
The advantages mentioned above are that there are corresponding advantages in special situations, such as decoupling, asynchronism and peak clipping. The disadvantages are as follows:
Reduced system availability: the more external dependencies the system introduces, the easier it is to fail. If MQ dies, MQ dies and the whole system collapses, aren't you done?
Increased complexity of the system: add a MQ into the system, how can you make sure that the message is not consumed repeatedly? How to deal with the loss of messages?
How to ensure the sequence of message delivery? A lot of questions.
Consistency problem: when system An is processed and returns successfully, people think that your request will be successful; but the problem is, if two systems of BCD succeed in writing the database of two BD systems, as a result, system C fails to write the database. Your figures are inconsistent.
5. How to ensure the reliability of the message?
The message was lost in the process of MQ, MQ itself, and MQ in the process of consumption.
Producer to RabbitMQ: transaction mechanism and Confirm mechanism, note: transaction mechanism and Confirm mechanism are mutually exclusive, the two can not coexist, it will cause RabbitMQ error.
RabbitMQ itself: persistence, clustering, normal mode, mirror mode.
RabbitMQ to consumer: basicAck mechanism, dead letter queue, message compensation mechanism.
What are the common switch types in 6.RabbitMQ?
Fanout: routes all messages sent to the switch to all queues bound to the switch.
Direct: routes messages to queues that match BindingKey and RoutingKey exactly.
Topic:
RoutingKey is a period'.': delimited string. For example: szh.name.love
BindingKey is also a dot like RoutingKey. Delimited strings.
BindingKey can use * and # for fuzzy matching, * matches one word, and # matches multiple or 0
7. What is the process of sending a message by a producer?
Producer first connects to Broker, establishes a connection Connection, and opens a channel (Channel).
Producer declares a switch and sets the relevant properties.
Producer declares a queue and sets the relevant properties.
Producer binds the switch to the queue through the routing key.
Producer sends messages to Broker containing routing keys, switches, and other information.
The corresponding switch looks for a matching queue according to the received routing key.
If found, the message is stored in the corresponding queue, and if not found, it will be discarded or returned to the producer according to the producer's configuration.
Close the channel, close the connection.
8. What is the process for consumers to receive messages?
Producer first connects to Broker, establishes a connection Connection, and opens a channel (Channel).
The message in the queue that requests the Broker to consume the response may set the callback function for the response.
Wait for the Broker to respond and deliver the message in the corresponding queue to receive the message.
The consumer confirms the receipt of the message, ack.
RabbitMQ removes determined messages from the queue.
Close the channel, close the connection.
9. What are the ways to deal with a switch that cannot find a qualified queue based on its own type and routing key?
Mandatory: true returns a message to the producer.
Mandatory: false discards directly.
10. What is a dead letter queue? What are the reasons for the dead letter?
Dead letter, DLX, full name Dead-Letter-Exchange, dead letter switch, dead letter mailbox. As the name implies, messages cannot be consumed. Generally speaking, producer delivers messages to broker or directly to queue. Consumer takes messages from queue for consumption, but sometimes some messages in queue cannot be consumed due to specific reasons. If there is no subsequent processing, such messages will become dead letters, and dead letters will naturally lead to dead letter queues.
Message TTL expired
The queue reaches the maximum length (the queue is full and no more data can be added to the mq)
The message is rejected (basic.reject or basic.nack) and requeue=false.
11. What is a delay queue? What are the usage scenarios?
Store the corresponding delayed message, which means that when the message is sent, the consumer does not want to get the message immediately, but waits for a specific time before the consumer can get the message for consumption.
If the order is not paid within ten minutes, it will be cancelled automatically.
If the newly created store has not uploaded the product within ten days, it will automatically send a message reminder.
After successful registration, users will be reminded by SMS if they do not log in within three days.
The user initiates a refund and notifies the relevant operators if it is not processed within three days.
After a scheduled meeting, participants need to be notified ten minutes in advance of the scheduled time to attend the meeting.
twelve。 What is a priority queue?
Queues with high priority are consumed first.
This can be done through the x-max-priority parameter.
Priority is meaningless when the consumption speed is faster than the production speed and the Broker is not stacked.
Transaction mechanism in 13.RabbitMQ?
There are three methods related to the transaction mechanism in the RabbitMQ client:
Channel.txSelect is used to set the current channel to transaction mode.
Channel.txCommit is used to commit transactions.
Channel.txRollback is used for transaction rollback, and if an exception is thrown due to an RabbitMQ exception crash or other reason before the transaction commits execution, roll back through txRollback.
Send confirmation mechanism in 14.RabbitMQ?
The producer sets the channel to confirm mode. Once the channel enters confirm mode, all messages posted on the channel will be assigned a unique ID (starting from 1). Once the message is delivered to all matching queues, broker will send an acknowledgement to the producer (the only ID containing the message), which allows the producer to know that the message has reached the destination queue correctly.
The biggest advantage of confirm mode is that it is asynchronous. Once a message is released, the producer application can continue to send the next message while waiting for the channel to return confirmation. When the message is finally acknowledged, the producer application can process the confirmation message through the callback method. If RabbitMQ loses the message due to its own internal error, it will send a nack message. The producer application can also process the nack message in the callback method.
15. How to ensure the high availability of RabbitMQ message queues?
There are three modes of RabbitMQ: stand-alone mode, normal cluster mode, and mirror cluster mode.
Stand-alone mode: it is at the demo level. Generally speaking, you start playing locally, and no one produces the stand-alone mode.
Normal cluster mode: it means to start multiple RabbitMQ instances on multiple machines, one for each machine.
Image cluster mode: this mode is the so-called high availability mode of RabbitMQ. Unlike the normal cluster mode, the queue you create, no matter the metadata (metadata refers to the configuration data of RabbitMQ) or the messages in queue will exist on multiple instances, and then each time you write a message to queue, it will automatically synchronize the message to the queue of multiple instances.
Thank you for your reading, the above is the content of "what are the Java RabbitMQ interview questions?" after the study of this article, I believe you have a deeper understanding of what the Java RabbitMQ interview questions have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.