RabbitMq exchange four ways

    

 

    When you send a message to the broker, the message will have a routing key (even if it is empty) and RabbitMQ will match it with the routing key used by the binding. If there is a match, the message will be posted to the queue. If the routed message does not match any binding pattern, the message will go into a "black hole". There are four exchange types: direct (default), fanout, topic and headers.

1. Direct
    Direct Exchange: One-to-one exact match, a queue needs to be bound to the exchange, and the message is required to exactly match a specific routing key.



2. Fanout
    Fanout Exchange: One -to-many exact match. You simply bind the queue to the exchange. A message sent to an exchange is forwarded to all queues bound to the exchange. Much like subnet broadcasts, hosts on each subnet get a copy of the message. Fanout switches are the fastest to forward messages.




Third, topic
    Topic Exchange : many-to-many regular matching. At this point the queue needs to be bound to a schema. The symbol "#" matches one or more words, and the symbol "*" matches no more than one word. So "audit.#" can match "audit.irs.corporate", but "audit.*" will only match "audit.irs"



Fourth, headers
    headers Exchange: The headers exchange allows you to match the headers of AMQP messages instead of routing key. Other than that, the headers exchange is exactly the same as the direct exchange, but the performance will be much worse. So it's not very practical, and it's almost never used again.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326218974&siteId=291194637