Asynchronous messages are useful for high-concurrency peak clipping in systems. In order to meet the subscription and processing of messages in SAAS platforms, a message processing microservice has been designed recently. Its core uses MQ’s priority queue mechanism to send messages, receive and process them.

1. MQ priority messages

RabbitMq provides the concept of priority queues and priority messages. To use priority, a queue must be identified as a priority queue, and then the priority of the routing message is set. In the case of slow processing, the message with higher priority is pushed to the processor first, so that the effect of processing with higher priority is processed first. Setup code is very simple, as shown in the following example:

// Define an Exchange
  channel.ExchangeDeclare(MQueue.Exchange.ExchangeName, MQueue.Exchange.ExchangeType, MQueue.Exchange
Copy the code