Yes, you can use MNS to send and receive multiple messages at a time. The batch processing feature increases queries per second (QPS), reduces requests, and minimize costs.

When you call API operations to send or receive messages at a time, take note of the following limits:

  • You can call the BatchPutMessage operation to send up to 16 messages at a time. The total size of the messages cannot exceed 64 KB.
    • By default, messages are Base64-encoded. A Base64-encoded message body is larger than the original message body. Therefore, the total size of the original messages cannot exceed 47 KB.
    • You can run the following command to disable the Base64 encoding feature. If Base64 encoding is disabled, the original messages are sent.
      message.setMessageBody("message_body", Message.MessageBodyType.RAW_STRING);
    • For information about how to send more than 64 KB of messages at a time, see Transfer oversized messages.
  • You can call the BatchReceiveMessage operation to receive up to 16 messages at a time. However, in some cases, the number of received messages is less than the number of available messages even if the upper limit is not reached.

    For example, 10 messages (m1, m2, m3, m4, m5, m6, m7, m8, m9, and m10) are sent in order. When you call the BatchReceiveMessage operation for the first time, 5 messages (m2, m4, m6, m8, and m10) are received. When you call the BatchReceiveMessage operation for the second time, the other 5 messages (m1, m3, m5, m7, and m9) are received.

    This is because data is stored as multiple stripes in MNS and each batch operation retrieves data from only one stripe. Therefore, the data stripes determine the messages that are retrieved in each batch. MNS does not guarantee the consistency of the order in which messages are produced and consumed.

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