RabbitMQ (2)-working mode

 

The last chapter RabbitMQ (1)-Introduction We have learned some simple knowledge of RabbitMQ. This chapter records the types of RabbitMQ and their respective characteristics.

 

RabbitMQ working mode:

  Simple model: one producer, one consumer.

  Work queue mode: one producer, multiple consumers, each consumer gets a unique message, by default polling.

  

Exchange mode:

  Publish / subscribe model (Fanout): messages sent by a producer will be obtained by multiple consumers. Messages sent to Fanout Exchange will be forwarded to all Queues that are bound to the Exchange. This mode does not require any Routekey. Exchange and Queue need to be bound in advance. One Exchange can be bound to multiple Queues, and one Queue can be bound to multiple Exchanges. If the Exchange receiving the message is not bound to any Queue, the message will be lost.

  

 

  Routing mode (Direct): Any message sent to Direct Exchange will be forwarded to the Queue specified by RouteKey. In this mode, there is no need to perform any binding operations on Exchange. A RouteKey is required for message delivery, which can be easily understood The name of the queue to be sent to. If the queue name does not exist in vhost, the message will be lost.

 

 

  Matching subscription mode (Topic): Any message sent to Topic Exchange will be forwarded to all Queues that care about the topics specified by RouteKey. That is, each queue has its subject of interest, and all messages have a header (RouteKey), and Exchange will forward the message to all queues of interest that can match the RouteKey fuzzy match. This mode requires Routekey and binds Exchange and Queue in advance. When binding, provide a theme corresponding to the queue. '#' Means 0 or several keywords, '*' means a keyword. If Exchange does not find a Queue that matches RouteKey, the message will be lost.

 

  headers: The headers exchange is mainly matched by the header in the request message sent. The matching rules (x-match) are divided into all and any, all means that all key-value pairs must match, any means that as long as there is a key-value pair match That's it. The default matching rule (x-match) for headers exchange is any.

 

Simple mode and work queue mode

  These two models are very simple and only involve producers, queues, and consumers.

  The producer is responsible for producing messages, sending the messages to the queue, and the consumers listening to the queue, and the queue consumes the messages.

  The work queue model is actually a simple model with multiple consumers.

  When there are multiple consumers, consumers consume messages in the queue on average.

Publish / subscribe, routing and topic mode

  These three modes will use Exchange. The producer does not directly interact with the queue, but sends the message to the switch, and then the switch sends the message to the queue that has been bound to the switch for consumer consumption.

  There are three types of commonly used switches: fanout, direct, and topic.

 

 

  Fanout does not handle routing keys, much like subnet broadcasts, each host in the subnet gets a copy of the message.

 

  The publish / subscribe model refers to the fanout exchange model. Fanout type switches forward messages the fastest.

 

 

  Direct mode handles routing keys, and routing keys need to match before they can be forwarded. The routing mode uses direct type switches.

 

 

 

  topic: Match the routing key with a pattern.

 

  Topic mode uses topic type switches.

 

 

 

Guess you like

Origin www.cnblogs.com/zousc/p/12725405.html