RabbitMQ learning-the eighth chapter RabbitMQ three Exchange mode performance comparison

In RabbitMQ, all messages submitted by producers are accepted by Exchange, and then Exchange is forwarded to Queue for storage according to a specific strategy.

RabbitMQ provides four types of Exchange: fanout, direct, topic, and header.

Header mode is less in actual use, this article only compares the first three modes.

Performance ranking : fanout> direct> topic. The ratio is approximately 11: 10: 6

1. Direct Exchange

Insert picture description here

Any message sent to Direct Exchange will be forwarded to the Queue specified in RouteKey.

1. In general, you can use the Exchange that comes with rabbitMQ: "" (the name of the Exchange is an empty string, hereinafter referred to as default Exchange).

2. In this mode, there is no need to perform any binding operation on Exchange.

3. A "RouteKey" is required for message delivery, which can be simply understood as the name of the queue to be sent to.

4. If the queue name specified in RouteKey does not exist in vhost, the message will be discarded.

二.Fanout Exchange

Insert picture description here

Any message sent to Fanout Exchange will be forwarded to all Queues bound to the Exchange.

1. Can be understood as the routing table mode

2. This mode does not require RouteKey

3. This model requires binding Exchange and Queue in advance. One Exchange can bind multiple Queues, and one Queue can be bound to multiple Exchanges.

4. If the Exchange that received the message is not bound to any Queue, the message will be discarded.

三.Topic Exchange

Insert picture description here

Any message sent to Topic Exchange will be forwarded to all Queues that care about the topic specified in RouteKey

1. This model is more complicated. In simple terms, each queue has its subject of interest. All messages have a "title" (RouteKey). Exchange will forward the message to all concerned topics. It can be blurred with RouteKey. Matching queue.

2. This mode requires RouteKey, and maybe you need to bind Exchange and Queue in advance.

3. When binding, provide a topic that the queue cares about, such as "# .log. #" Means that the queue cares about all messages related to log (a message with RouteKey "MQ.log.error" will be forwarded To the queue).

4. "#" means 0 or several keywords, "*
" means one keyword. For example, "log. *" Can match "log.warn", but not "log.warn.timeout"; but "log. #" Can match both.

"rn" matches and cannot match "log.warn.timeout"; but "log. #" can match both.

5. Similarly, if Exchange does not find a Queue that matches RouteKey, it will discard this message.

Published 40 original articles · 25 praises · 100,000+ views

Guess you like

Origin blog.csdn.net/yym373872996/article/details/105653727