edit-icon download-icon

Considerations for batch message operations in the message service

Last Updated: Mar 23, 2017

The Message Service provides interfaces for sending and receiving messages in batches, which not only improves QPS, but also reduces the number of requests and the cost.

  • The BatchPutMessage interface can be used to send up to 16 messages at a time. The total size of the sent messages cannot exceed 64 KB.

    Unless specified, the sent messages is Base64 encoded by default (the original message body is amplified). Therefore, the actual size of the sent messages cannot exceed 47 KB.

    You can run the following command to cancel Base64 encoding and use the original message body:

    1. message.setMessageBody(“message_body”, Message.MessageBodyType.RAW_STRING);
  • The BatchReceiveMessage interface can be used to receive up to 16 messages at a time.

    But why BatchReceiveMessage can only receive five messages when there are ten messages?

    Here is the test: Ten messages in a queue are sent in sequence (m1, m2, m3, m4, m5, m6, m7, m8, m9 and m10). The first call of BatchReceiveMessage consumes five messages (m2, m4, m6, m8 and m10), and the second call of BatchReceiveMessage consumes the remaining five messages (m1, m3, m5, m7 and m9).

    The Message Service stores data in multiple slices and fetches data only from one slice at each batch fetch operation. After fetching the required data, the Message Service immediately returns, instead of waiting until fetching data from all slices. When data is sent, how the slices are distributed determines which messages are returned at each batch fetch operation.

    That is one of the reasons why the Message Service does not ensure the consumed order of messages.

    If the problem persists, contact Alibaba Cloud After-Sales Technical Support.  

Thank you! We've received your feedback.