When a message is sent through the Message Service, the priority value of the message can be specified. (The value ranges from 1 to 16. “1” indicates the highest priority. The default priority is “8”.) A message with a higher priority is more likely to be consumed earlier.
Is a message having a priority value of 1 certainly consumed earlier than that valued with 2?
Here is a test:
100 messages are sent in sequence, in which the priority value of the 50th message is 1 and the value of the rest is 8 by default.
CloudQueue queue = createQueue();
Message message = new Message();
Message putMsg = queue.putMessage(message);
System.out.println(“PutMessage MsgId: ” + putMsg.getMessageId()+”,priority=”+ putMsg.getPriority());
The result shows that neither messages called out by pop are generally in sequence nor the msg-50 is first consumed.
The Message Service tries its best to ensure that messages are consumed in an FIFO manner. However, due to some features of distributed message queues, it cannot be ensured that you can consume messages in the order they are sent. If your service requires FIFO, it is recommended that you add sequence numbers to messages so that the messages are resorted after consumption.
The priority of a message in the Message Service is partial instead of general.
Put it in another way: the messages are stored in multiple channels and those stored in the same channel are called slices. The priority setting only takes effect to a slice in which lies a message with a higher priority.
For example, if the first slice contains a message with a higher priority, the Message Service will first return messages in this slice. If not, the Message Service may still first return messages in this slice.
That’s one of the reasons why the Message Service supports a high QPS but does not ensure the consumed order of messages.
If you have further questions, contact Alibaba Cloud After-Sales Technical Support.