Class: QueueService

QueueService

The QueueService class is used to perform operations on the Windows Azure Queue Service.

For more information on using the Queue Service, as well as task focused information on using it from a Node.js application, see How to Use the Queue Service from Node.js.

new QueueService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider)

Creates a new QueueService object. If no storageAccount or storageAccessKey are provided, the AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY environment variables will be used.

Parameters:
Name Type Argument Description
storageAccountOrConnectionString string <optional>

The storage account or the connection string.

storageAccessKey string <optional>

The storage access key.

host string <optional>

The host address.

authenticationProvider object <optional>

The authentication provider.

Source:

Extends

  • ServiceClient

Methods

clearMessages(queue, options, callback)

Clears all messages from the queue.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

options object <optional>

The delete and request options.

Properties
Name Type Argument Description
timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise response will contain information related to this operation.

Source:

createMessage(queue, messageText, options, callback)

Adds a new message to the back of the message queue. A visibility timeout can also be specified to make the message invisible until the visibility timeout expires. A message must be in a format that can be included in an XML request with UTF-8 encoding. The encoded message can be up to 64KB in size for versions 2011-08-18 and newer, or 8KB in size for previous versions.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

messageText object

The message text.

options object <optional>

The put and request options.

Properties
Name Type Argument Description
messagettl int <optional>

The time-to-live interval for the message, in seconds. The maximum time-to-live allowed is 7 days. If this parameter is omitted, the default time-to-live is 7 days

visibilitytimeout int <optional>

Specifies the new visibility timeout value, in seconds, relative to server time. The new value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message cannot be set to a value later than the expiry time. visibilitytimeout should be set to a value smaller than the time-to-live value.

timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueMessageResult will contain the result. response will contain information related to this operation.

Source:
Example
var azure = require('azure');
var queueService = azure.createQueueService();
queueService.createMessage('taskqueue', 'Hello world!', function(error) {
  if(!error) {
    // Message inserted
  }
});

createQueue(queue, options, callback)

Creates a new queue under the given account.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

options object <optional>

The create and request options.

Properties
Name Type Argument Description
metadata object <optional>

The metadata key/value pairs.

timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueResult will contain the queue information. response will contain information related to this operation.

Source:

createQueueIfNotExists(queue, options, callback)

Creates a new queue under the given account if it doesn't exist.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

options object <optional>

The create and request options.

Properties
Name Type Argument Description
metadata object <optional>

The metadata key/value pairs.

timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueCreated will contain the queue information. response will contain information related to this operation.

Source:
Example
var azure = require('azure');
var queueService = azure.createQueueService();
queueService.createQueueIfNotExists('taskqueue', function(error) {
  if(!error) {
    // Queue created or exists
  }
}); 

deleteMessage(queue, messageid, popreceipt, options, callback)

Deletes a specified message from the queue.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

messageid string

The message identifier of the message to delete.

popreceipt string

A valid pop receipt value returned from an earlier call to the Get Messages or Update Message operation

options object <optional>

The delete and request options.

Properties
Name Type Argument Description
timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise successful will contain true if the operation was successful. response will contain information related to this operation.

Source:

deleteQueue(queue, options, callback)

Permanently deletes the specified queue.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

options object <optional>

The delete and request options.

Properties
Name Type Argument Description
timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise deleted will contain true if the operation was successful. response will contain information related to this operation.

Source:

getMessages(queue, options, callback)

Retrieves a message from the queue and makes it invisible to other consumers.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

options object <optional>

The get and request options.

Properties
Name Type Argument Description
numofmessages int <optional>

A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. By default, a single message is retrieved from the queue with this operation.

peekonly bool <optional>

Boolean value indicating wether the visibility of the message should be changed or not.

visibilitytimeout int <optional>

Required if not peek only. Specifies the new visibility timeout value, in seconds, relative to server time. The new value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message can be set to a value later than the expiry time.

timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueMessageResults will contain the message. response will contain information related to this operation.

Source:
Example
var azure = require('azure');
var queueService = azure.createQueueService();
var queueName = 'taskqueue';
queueService.getMessages(queueName, function(error, serverMessages) {
  if(!error) {
    // Process the message in less than 30 seconds, the message
    // text is available in serverMessages[0].messagetext
    queueService.deleteMessage(queueName, serverMessages[0].messageid, serverMessages[0].popreceipt, function(error) {
      if(!error){
          // Message deleted
      }
    });
  }
});

getQueueMetadata(queue, options, callback)

Returns queue properties, including user-defined metadata.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

options object <optional>

The get and request options.

Properties
Name Type Argument Description
timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueResult will contain the queue information. response will contain information related to this operation.

Source:

getServiceProperties(options, callback)

Gets the properties of a storage account’s Queue service, including Windows Azure Storage Analytics.

This:
Parameters:
Name Type Argument Description
options object <optional>

The request options.

Properties
Name Type Argument Description
timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise, serviceProperties will contain the properties and response will contain information related to this operation.

Source:

listQueues(options, callback)

Lists all queues under the given account.

This:
Parameters:
Name Type Argument Description
options object <optional>

The listing and request options.

Properties
Name Type Argument Description
prefix string <optional>

Filters the results to return only queues whose name begins with the specified prefix.

marker string <optional>

String value that identifies the portion of the list to be returned with the next list operation.

maxresults int <optional>

Specifies the maximum number of queues to return per call to Azure storage. This does NOT affect list size returned by this function. (maximum: 5000)

include string <optional>

Include this parameter to specify that the queue's metadata be returned as part of the response body. (allowed values: '', 'metadata')

timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueResults will contain a list of queue objects, and response will contain information related to this operation. If not all queue information could be retrieved, nextMarker will contain a value that can be used to retrieve the next section of the queue list.

Source:

peekMessages(queue, options, callback)

Retrieves a message from the front of the queue, without changing the message visibility.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

options object <optional>

The peek and request options.

Properties
Name Type Argument Description
numofmessages int <optional>

A nonzero integer value that specifies the number of messages to retrieve from the queue, up to a maximum of 32. By default, a single message is retrieved from the queue with this operation.

timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueMessageResults will contain the message. response will contain information related to this operation.

Source:

setQueueMetadata(queue, metadata, options, callback)

Sets user-defined metadata on the specified queue. Metadata is associated with the queue as name-value pairs.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

metadata object

The metadata key/value pairs.

options object <optional>

The set and request options.

Properties
Name Type Argument Description
timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueResult will contain the queue information. response will contain information related to this operation.

Source:

setServiceProperties(serviceProperties, options, callback)

Sets the properties of a storage account’s Queue service, including Windows Azure Storage Analytics. You can also use this operation to set the default request version for all incoming requests that do not have a version specified.

This:
Parameters:
Name Type Argument Description
serviceProperties object

The service properties.

options object <optional>

The request options.

Properties
Name Type Argument Description
timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise, response will contain information related to this operation.

Source:

updateMessage(queue, messageid, popreceipt, visibilitytimeout, options, callback)

Updates the visibility timeout of a message. You can also use this operation to update the contents of a message. A message must be in a format that can be included in an XML request with UTF-8 encoding, and the encoded message can be up to 64KB in size.

This:
Parameters:
Name Type Argument Description
queue string

The queue name.

messageid string

The message identifier of the message to update.

popreceipt string

A valid pop receipt value returned from an earlier call to the Get Messages or Update Message operation

visibilitytimeout int

Specifies the new visibility timeout value, in seconds, relative to server time. The new value must be larger than or equal to 0, and cannot be larger than 7 days. The visibility timeout of a message can be set to a value later than the expiry time.

options object <optional>

The delete and request options.

Properties
Name Type Argument Description
messagetext object <optional>

The new message text.

timeoutIntervalInMs int <optional>

The timeout interval, in milliseconds, to use for the request.

callback function

error will contain information if an error occurs; otherwise queueMessageResult will contain the message result information. response will contain information related to this operation.

Source: