Rabbitmq-about exchangetypes

Source: Internet
Author: User
Tags rabbitmq

Summarize several types of exchangetypes.



Exchange type was mentioned for the first time when I wrote the publishing/subscription mode.

That is, the producer does not directly put messages in the queue, but first goes to exchange. Exchange is mainly used to control the route of messages to the queue. Based on the specific exchange type, messages are sent to the required queue or directly discarded.

In this article, we will summarize the exchange types used.



1. Direct Exchange

Direct exchange is the most basic.

Direct Exchange is used to transmit messages with the same routing key to a queue.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/43/CB/wKiom1Pcxzvj1E7gAACkScAi_wQ990.jpg "Title =" direct.png "style =" white-space: normal; float: none; "alt =" wkiom1pcxzvj1e7gaackscai_wq990.jpg "/>

When we want to use a simple identifier to distinguish all messages passed into the same exchange, direct exchange is very suitable.



Ii. fanout exchange

Fanout has nothing to do with the routing key. It transmits messages to all queues without any difference.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/43/CC/wKioL1PcyFXBJmrxAADDEEnK_f0528.jpg "Title =" fanout.png "style =" white-space: normal; float: none; "alt =" wkiol1pcyfxbjmrxaaddeenk_f0528.jpg "/>

Fanout exchange is usually used in publish/subscribe mode.

Send messages to different queues. Different queues take different actions on the same message.

For example, a customer's order message is now received by three queues. Queue 1 completes the order, queue 2 writes the order to the log, and queue 3 sends the order to another department.



3. Topic exchange

Topic exchange is more difficult to describe its features.

Topic exchange is based on a topic rather than a specific title, that is, it can match part or all of the routing key.

The routing key of topic exchange can contain multiple words separated.

The routing key can include '*' or '#', '*' to indicate a word, and '#' to indicate 0 ~ N words.


For example, when a message is published, the routing key is "Honda. Civic. Navy ",

The routing key of the queue that can receive messages can be "Honda. Civic. Navy" or "*. Civic. *" or "Honda. #" or "#",

But it cannot be "Honda. Accord. Navy" or "Honda. Accord. Silver" or "*. Accord. *" or "Ford .#". 650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/43/CB/wKiom1PcxzzhelfhAAFy4q7WNsI109.jpg "Title =" topic.png "style =" float: none; "alt =" wkiom1pcxzzhelfhaafy4q7wnsi109.jpg "/>



Iv. headers exchange

That is, the communication can be performed when the message header matches the message header declared in the queue.

When multiple conditions can be defined for matching, header exchange is similar to topic exchange, but it does not depend on the routing key at all, but uses a set of Kv pairs for matching.

650) This. length = 650; "src =" http://s3.51cto.com/wyfs02/M00/43/CD/wKioL1Pc2GOyXIBUAAE8-dcocsg118.jpg "Title =" header.png "width =" 600 "Height =" 220 "border =" 0 "hspace =" 0 "vspace =" 0 "style =" Width: 600px; Height: 220px; "alt =" wKioL1Pc2GOyXIBUAAE8-dcocsg118.jpg "/>



(PS: the figure is good. I would like to pay tribute to the original author .)

This article is from the "alvez. 99.9% 0b/s" blog, please be sure to keep this source http://alvez.blog.51cto.com/7711135/1534276

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.