- Work Queue Work Queue mode
- Publish/Subscribe Publish/Subscribe mode
- Routing Routing mode
- Switchable viewer wildcard
- The Header repeater
- RPC remote call
Work Queue Specifies the Work Queue mode
- A producer sends a message to a queue
- Multiple consumers listen to the same queue
- Messages cannot be re-consumed
- RabbitMq uses polling to evenly send messages to consumers
Publish/Subscribe
- The producer sends the message to the switch
- There are multiple queues bound to the switch, and each consumer listens to its own queue
- The producer sends the message to the switch, which forwards the message to the queue bound to the switch, and each queue bound to the switch receives the message
What is the difference between Publish/Subscribe and Work Queue?
Publish/ subscribe can bind a switch to multiple queues. A message can be sent to multiple queues. A message can be sent to only one queue. Multiple consumers can also listen to the same Queue to achieve the function of Work Queue
Routing mode
- A switch is bound to multiple queues, each queue sets a routingKey, and a queue can set multiple Routingkeys
- Each consumer listens to its own queue
- The producer sends the message to the switch, which needs to specify a routingKey value when sending the message. The switch determines which routingKey value is equal to the routingKey of the queue, and forwards the message to the queue if the value is equal
Routing mode and Publish/Subscribe mode?
RoutingKey (routingKey) routingKey (routingKey) routingKey (routingKey) routingKey (routingKey) Send a message to a queue with a routingKey value equal to the routingKey value, as shown in the figure above. Each queue can specify multiple Routingkeys. If the routingKey value is error when sending a message, since both C1 and C2 routingkeys are error, So the message is sent to C1 and C2. If the routingKey is specified as Info, only C2 can receive the message. 3. Routing is more powerful and can Publish/Subscribe
4. Topics Mode
- A switch can bind to multiple queues, and each queue can have one or more routingkeys with wildcards
- The producer sends the message to the switch, which matches the queue based on the Value of the routingKey, using wildcards, and forwards the message to the specified queue.
The difference between Topics and Routing?
Topics 1. The basic principle of Topics and Routing is the same, that the producer sends the message to the switch and the switch forwards the message to a queue that matches the routingKey. 2. The differences are: routingKey matching mode, Routing mode is equal matching, Topics mode is wildcard matching
Symbol # : Matches one or more words (with each word in the middle. * : matches only one word, for example, inform.* matches informCopy the code
5. Header mode
The header pattern differs from routing in that it discards the routingKey and uses the key/value key-value pairs in the header to match the queue
Sixth, the RPC
RPC is a method that the client remotely invokes the server. MQ can be used to realize asynchronous invocation of RPC, based on the Direct switch. The process is as follows:
- The client, both producer and consumer, sends RPC call messages to the RPC request queue and listens to the RPC response queue
- The server listens to the message in the RPC request queue, executes the method of the server after receiving the message, and gets the result returned by the method
- The server sends the result of the RPC method to the RPC response queue
RabbitMq delay queue implementation principle:
RabbitMq 1, RabbitMq can set x-message-TTL for messages and queues to control the duration of messages. If the timeout message changes to a dead letter, configure the x-dead-letter-exchange and x-dead-letter-routing parameters to control the occurrence of a dead letter in the RabbitMq Queue. Destination for resending messages For example, set the duration of a message to 10 seconds