All Products
Search
Document Center

Simple Message Queue (formerly MNS):Short polling and long polling

Last Updated:Oct 29, 2024

Simple Message Queue (SMQ, formerly MNS) provides two polling methods for you to receive messages from queues.

Short polling

  • To use short polling, set the long polling period to 0 when you create a queue and set the waitSeconds parameter to 0 when you call an API operation to receive messages.

  • If you use short polling to receive messages from a queue, a request is sent to the server of the SMQ cluster and a response is immediately returned regardless of whether a message exists.

Long polling

  • To use long polling, set the long polling period to a value greater than 0 when you create a queue. Alternatively, set the waitSeconds parameter to a value greater than 0 when you call an API operation to receive messages. The maximum value of a long polling period is 30 seconds. The long polling period specified by the waitSeconds parameter in an API request takes precedence over the long polling period specified for the queue.

  • If you use long polling to receive messages from a queue, a request is sent to the server, and a response is returned only if a message exists. This ensures that you can immediately receive messages and prevents you from sending invalid requests, which reduces the number of requests and saves costs.

Usage notes

If you send a large number of API requests to receive messages but only the response indicating that no message exists is returned, we recommend that you increase the long polling period to reduce the number of requests and save costs.