RABBITMQ, messages submitted by all producers are accepted by Exchange, and exchange is forwarded to the queue for storage according to a specific policy
RABBITMQ offers four types of Exchange:fanout,direct,topic,header
The header pattern is less in practice, compared with the first three modes in this article.
Performance sequencing: fanout > Direct >> topic. The ratio is approximately 11:10:6
One. Direct Exchange
any messages sent to direct Exchange will be forwarded to the queue specified in Routekey.
1. In general, you can use RABBITMQ's own Exchange: "" (The Exchange name is an empty string, which is referred to as default Exchange).
2. No binding (binding) action is required for Exchange in this mode
3. Message delivery requires a "routekey" that can be simply understood as the name of the queue to be sent to.
4. If the queue name specified in the Routekey does not exist in the Vhost, the message is discarded.
Two.fanout Exchange
Any messages sent to Fanout Exchange will be forwarded to all the queue with that exchange binding (binding).
1. Patterns that can be understood as routing tables
2. This mode does not require Routekey
3. This mode requires Exchange to be bound with the queue in advance, one exchange can bind multiple queues, and one queue can bind to multiple exchange.
4. If exchange that receives the message is not bound to any queue, the message is discarded.
Three.Topic Exchange
Any messages sent to topic Exchange will be forwarded to all queues that are concerned with the specified topic in Routekey
1. This mode is more complex, simply put, is that each queue has its own topic of interest, all messages with a "title" (Routekey), Exchange will forward the message to all the topics of interest can match the Routekey fuzzy queue.
2. This mode requires Routekey, perhaps to bind exchange and queue in advance.
3. When binding, to provide a topic that the queue cares about, such as "#.log.#" means that the queue is concerned with all messages involving log (a message Routekey "MQ.log.error" is forwarded to the queue).
4. "#" means 0 or more keywords, and "*" denotes a keyword. such as "log.*" can Match "Log.warn", cannot match "log.warn.timeout", but "log.#" can match the above two.
5. Similarly, if Exchange does not find a queue that can match Routekey, this message is discarded.
RABBITMQ Performance Comparison of three Exchange modes (FANOUT,DIRECT,TOPIC)