Talk about those things about RabbitMQ

Interview-oriented blogs are presented in Q / A style.


Question1: Briefly introduce the RabbitMQ message queue?

Answer1:

RabbitMQ is an open source implementation of AMQP (Advanced Message Queuing Protocol) developed by Erlang.

AMQP: Advanced Message Queue Protocol, Advanced Message Queue Protocol. It is an open standard for application layer protocols and is designed for message-oriented middleware. Clients and message middleware based on this protocol can deliver messages without being restricted by conditions such as products and development languages.

RabbitMQ originally originated in the financial system and is used to store and forward messages in distributed systems. It performs well in terms of ease of use, scalability, and high availability. Specific features include:

  1. Reliability: RabbitMQ uses some mechanisms to ensure reliability, such as persistence, transmission confirmation, and release confirmation.
  2. Flexible routing (Flexible Routing): Before the message enters the queue, the message is routed through Exchange. For typical routing functions, RabbitMQ has provided some built-in Exchange to achieve. For more complex routing functions, you can bind multiple Exchanges together, and also implement your own Exchange through a plug-in mechanism.
  3. Clustering: Multiple RabbitMQ servers can form a cluster to form a logical broker.
  4. Highly Available (Highly Available Queues): The queue can be mirrored on the machines in the cluster, so that the queue is still available in case of problems with some nodes.
  5. Multi-protocol: RabbitMQ supports multiple message queue protocols, such as STOMP, MQTT, etc.
  6. Multi-language clients (Many Clients): RabbitMQ supports almost all commonly used languages, than Java, .NET, Ruby, etc.
  7. Management UI: RabbitMQ provides an easy-to-use user interface that allows users to monitor and manage many aspects of the message broker.
  8. Tracing mechanism: If the message is abnormal, RabbitMQ provides a message tracking mechanism, the user can find out what happened.
  9. Plug-in mechanism (Plugin System): RabbitMQ provides many plug-ins to extend from many aspects, you can also write your own plug-ins.

Question2: Briefly introduce the RabbitMQ architecture?

Answer2:

RabbitMQ architecture, as shown below:
Insert picture description here
1, Message
message, the message is unnamed, it consists of a message header and a message body. The message body is opaque, and the message header is composed of a series of optional attributes, these attributes include routing-key (routing key), priority (priority relative to other messages), delivery-mode (indicating that the message may need Persistent storage) etc.

2.
The producer of Publisher messages is also a client application that publishes messages to the exchange.

3. Exchange (routing messages to the queue)
exchange, used to receive messages sent by the producer and route these messages to the queue in the server.

4. Binding (association between the message queue and the switch)
binding, used for the association between the message queue and the switch. A binding is a routing rule that connects the switch and the message queue based on the routing key, so the switch can be understood as a routing table composed of bindings.

5. Queue
message queue, used to save messages until they are sent to consumers. It is the container of the message and the end of the message. A message can be put into one or more queues. The message has been in the queue, waiting for consumers to connect to this queue to take it away.

6. Connection
network connection, such as a TCP connection.

7. Channel
channel, an independent bidirectional data flow channel in a multiplexed connection. The channel is a virtual connection established in the real TCP connection. AMQP commands are sent through the channel. Whether it is publishing a message, subscribing to a queue, or receiving a message, these actions are completed through the channel. Because it is very expensive for the operating system to establish and destroy TCP, the concept of channel is introduced to reuse a TCP connection.

8. Consumers of Consumer
messages represent a client application that gets messages from the message queue.

9. Virtual Host
, which represents a batch of switches, message queues and related objects. A virtual host is an independent server domain that shares the same identity authentication and encryption environment.

10. Broker
represents the message queue server entity.


Question3: Talk about different strategies for Exchange to distribute messages?

Answer3:

Exchange distributes messages according to different types of distribution strategies. There are currently four types: direct, fanout, topic, and headers. The headers match the header of the AMQP message instead of the routing key. In addition, the header switch and the direct switch are exactly the same, but the performance is much worse, and it is almost not used at present, so look directly at the other three types:

1. Direct key (routing key) distribution

Direct: If the routing key in the message is the same as the binding key in the Binding, the switch will send the message to the corresponding queue. It is a fully matched, unicast mode. Direct Exchange is shown below:

Insert picture description here

The above figure shows that under the direct type, when the routing key and the binding key exactly match, the routing key = key routing key = key in the figure exactly matches, and the switch sends the message to the corresponding queue, and finally the consumer from the message queue Take out the message for consumption.

2. Fanout (broadcast distribution)

Fanout: Every message sent to a fanout-type switch will be distributed to all bound queues (much like subnet broadcasting, each host in the subnet gets a copy of the message). Fanout type forwarding messages is the fastest.

Fanout Exchange is shown below:
Insert picture description here

The above figure shows that under the fanout type, all the messages of the switch are distributed to all bound queues like broadcast, and finally the consumer takes the messages from the message queue for consumption.

3. topic switch (pattern matching)

topic switch: The topic switch distributes the routing key attributes of a message through pattern matching to match the routing key with a certain pattern. In this case, the queue needs to be bound to a pattern. It splits the string of routing keys and binding keys into words, separated by dots. It also recognizes two wildcards: the symbol "#" and the symbol "". #Match 0 or more words, match no more than one word.

Topic Exchange is shown below:

Insert picture description here

The topic type and the direct type are similar in that the routing key and the binding key match. The difference is that when the direct type is the binding key is determined, the two are completely matched, and when the topic type is the binding key is a kind of Matching pattern, matching the routing key that matches this pattern, of course, there is more than one routing key that matches this pattern.
In the above picture, the pattern matching is:
binding.key = usa. # Matches routing.key = usa.news routing.key = usa.weather;
binding.key = #. News matches routing.key = usa.news routing.key = europe.news;
binding.key = #. weather matches routing.key = usa.weather routing.key = europe.weather;
binding.key = europe. # matches routing.key = europe.news routing.key = europe.weather.
After the pattern matching is satisfied, the switch sends the message to the corresponding queue, and finally the consumer takes the message from the message queue for consumption.

Published 207 original articles · praised 80 · 120,000 views

Guess you like

Origin blog.csdn.net/qq_36963950/article/details/105335758