This topic explains why the number of messages returned by the BatchSendMessage
operation is smaller than the number of visible messages in a queue.
Simple Message Queue (SMQ, formerly MNS) is deployed in a serverless architecture. In this architecture, a message queue corresponds to dozens or even hundreds of compute and storage nodes depending on the overall traffic and message usage in the region. As a result, consecutive messages may be stored on different nodes.
However, the BatchReceiveMessage
operation does not always receive messages across nodes. Instead, it selects a storage node in load balancing mode and attempts to receive the maximum number of messages on the node.
If the
BatchReceiveMessage
operation does not receive the specified number of messages on the node, it selects another node to receive more messages.If the
BatchReceiveMessage
operation receives the specified number of messages, it returns what it receives directly.This rapid return optimizes the performance of the operation, and all messages can be consumed as long as the operation continues being called.
Assume that you call the BatchReceiveMessage
operation, which reads a maximum of 15 messages in batches, in a queue that stores 11 messages on multiple nodes. The operation finds any node that stores messages and rapidly returns them. The node selected by the operation may store fewer than 11 messages, resulting in a number mismatch.