This topic describes message priorities and the order in which messages are consumed.

Messages are consumed based on the priorities of the messages. You can set a priority for a message in MNS. The priority ranges from 1 to 16. The value 1 indicates the highest priority. The default priority of a message is 8. A message with a higher priority is consumed earlier.

For example, 100 messages are sent in order. The priority of the 50th message is 1, and the priorities of the other messages are 8.

CloudQueue queue = createQueue();
     for(int i=1;i<=100;i++){
         Message message = new Message();
             message.setMessageBody("msg-"+i, Message.MessageBodyType.RAW_STRING);
             Message putMsg = queue.putMessage(message);
             System.out.println("PutMessage MsgId: " + putMsg.getMessageId());

However, the 50th message may not be the first to be consumed.

In MNS, a priority is valid only within a stripe. Messages are stored in multiple stripes. If the first stripe has a message with a higher priority, MNS retrieves the message first. If the messages in the first stripe have the same priority, MNS retrieves the messages in random order. Therefore, the data striping feature of MNS ensures high queries per second (QPS) but

MNS does not guarantee the order in which messages are consumed. If your business requires a strict message consumption order, add the SeqId parameter when you send messages to MNS so that the messages can be sorted at consumer clients.

For information about how to implement the first-in, first-out (FIFO) method in MNS, see Ensure the ordering of queue messages.