Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Solutions
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Message Queue
  • Getting started
    • Quick start
    • Supported tools
    • Code samples
      • Node.js
      • PHP
      • JMS
      • Laravel
      • Terraform
  • Step-by-step instructions
    • Overview
    • Creating a new message queue
    • Sending messages
    • Receiving and deleting messages
    • Deleting a message queue
  • Concepts
    • Overview
    • Message queues
    • Messages
    • Deduplication
    • Visibility timeout
    • Long Polling
    • Dead Letter Queue
    • Delay queues
    • Quotas and limits
  • Access management
  • Pricing policy
  • Yandex Message Queue API
    • Overview
    • Queue
      • CreateQueue
      • DeleteQueue
      • GetQueueAttributes
      • GetQueueUrl
      • ListQueues
      • PurgeQueue
      • SetQueueAttributes
    • Message
      • ChangeMessageVisibility
      • ChangeMessageVisibilityBatch
      • DeleteMessage
      • DeleteMessageBatch
      • ReceiveMessage
      • SendMessage
      • SendMessageBatch
    • Data types
      • BatchResultErrorEntry
      • ChangeMessageVisibilityBatchRequestEntry
      • ChangeMessageVisibilityBatchResultEntry
      • DeleteMessageBatchRequestEntry
      • DeleteMessageBatchResultEntry
      • Message
      • MessageAttributeValue
      • SendMessageBatchRequestEntry
      • SendMessageBatchResultEntry
    • Common errors
  • Questions and answers
  1. Concepts
  2. Long Polling

Long Polling

  • Usage
  • Advantages over Short Polling

The Long Polling technique is implemented to optimize the use of Yandex Message Queue by reducing the number of ReceiveMessage requests sent to empty queues. Instead of making repeated requests, Yandex Message Queue lets consumers wait for messages to arrive in a queue and read them immediately. In addition, a longer poll time allows Long Polling to avoid false empty responses.

Usage

You can use Long Polling by setting a non-zero value for the WaitTimeSeconds parameter of the ReceiveMessage method. This parameter determines how long a client will wait for messages to arrive in an empty queue. An empty response is returned to the client only after this time has passed. The maximum WaitTimeSeconds value is 20 seconds.

In response to ReceiveMessage, at least one of the messages from the queue is returned. The maximum number of messages to return is limited by the MaxNumberOfMessages parameter.

Advantages over Short Polling

Standard behavior of the ReceiveMessage method implies that the Short Polling technique is used: the method does not wait for messages to arrive in a queue, and only part of the queue's shards are polled when it is called. There might be no new messages in the selected shards, while new messages in the shards that have not been selected will remain unread. This results in false empty responses: ReceiveMessage reports no messages while there are messages in the queue.

Long Polling allows you to avoid false empty responses thanks to polling all the shards in the queue during the set wait time, and not just the shards selected when executing a request with the WaitTimeSeconds parameter set to zero.

In this article:
  • Usage
  • Advantages over Short Polling
Language / Region
Careers
Privacy policy
Terms of use
Brandbook
© 2021 Yandex.Cloud LLC