| StorageQueue {AzureQstor} | R Documentation |
R6 class representing an Azure storage queue
Description
A storage queue holds messages. A queue can contain an unlimited number of messages, each of which can be up to 64KB in size. Messages are generally added to the end of the queue and retrieved from the front of the queue, although first in, first out (FIFO) behavior is not guaranteed.
To generate a queue object, use one of the storage_queue, list_storage_queues or create_storage_queue functions rather than calling the new() method directly.
Public fields
endpointA queue endpoint object. This contains the account and authentication information for the queue.
nameThe name of the queue.
Methods
Public methods
Method new()
Initialize the queue object. Rather than calling this directly, you should use one of the storage_queue, list_storage_queues or create_storage_queue functions.
Note that initializing this object is a local operation only. If a queue of the given name does not already exist in the storage account, it has to be created remotely by calling the create method.
Usage
StorageQueue$new(endpoint, name)
Arguments
endpointAn endpoint object.
nameThe name of the queue.
Method create()
Creates a storage queue in Azure, using the storage endpoint and name from this R6 object.
Usage
StorageQueue$create()
Returns
The queue object, invisibly.
Method delete()
Deletes this storage queue in Azure.
Usage
StorageQueue$delete(confirm = TRUE)
Arguments
confirmWhether to ask for confirmation before deleting.
Returns
The queue object, invisibly.
Method clear()
Clears (deletes) all messages in this storage queue.
Usage
StorageQueue$clear()
Returns
The queue object, invisibly.
Method get_metadata()
Retrieves user-defined metadata for the queue.
Usage
StorageQueue$get_metadata()
Returns
A named list of metadata properties.
Method set_metadata()
Sets user-defined metadata for the queue.
Usage
StorageQueue$set_metadata(..., keep_existing = TRUE)
Arguments
...Name-value pairs to set as metadata.
keep_existingWhether to retain existing metadata information.
Returns
A named list of metadata properties, invisibly.
Method get_message()
Reads a message from the front of the storage queue.
When a message is read, the consumer is expected to process the message and then delete it. After the message is read, it is made invisible to other consumers for a specified interval. If the message has not yet been deleted at the time the interval expires, its visibility is restored, so that another consumer may process it.
Usage
StorageQueue$get_message()
Returns
A new object of class QueueMessage.
Method get_messages()
Reads several messages at once from the front of the storage queue.
When a message is read, the consumer is expected to process the message and then delete it. After the message is read, it is made invisible to other consumers for a specified interval. If the message has not yet been deleted at the time the interval expires, its visibility is restored, so that another consumer may process it.
Usage
StorageQueue$get_messages(n = 1)
Arguments
nHow many messages to read. The maximum is 32.
Returns
A list of objects of class QueueMessage.
Method peek_message()
Reads a message from the storage queue, but does not alter its visibility.
Note that a message obtained via the peek_message or peek_messages method will not include a pop receipt, which is required to delete or update it.
Usage
StorageQueue$peek_message()
Returns
A new object of class QueueMessage.
Method peek_messages()
Reads several messages at once from the storage queue, without altering their visibility.
Note that a message obtained via the peek_message or peek_messages method will not include a pop receipt, which is required to delete or update it.
Usage
StorageQueue$peek_messages(n = 1)
Arguments
nHow many messages to read. The maximum is 32.
Returns
A list of objects of class QueueMessage.
Method pop_message()
Reads a message from the storage queue, removing it at the same time. This is equivalent to calling get_message and delete_message successively.
Usage
StorageQueue$pop_message()
Returns
A new object of class QueueMessage.
Method pop_messages()
Reads several messages at once from the storage queue, and then removes them.
Usage
StorageQueue$pop_messages(n = 1)
Arguments
nHow many messages to read. The maximum is 32.
Returns
A list of objects of class QueueMessage.
Method put_message()
Writes a message to the back of the message queue.
Usage
StorageQueue$put_message(text, visibility_timeout = NULL, time_to_live = NULL)
Arguments
textThe message text, either a raw or character vector. If a raw vector, it is base64-encoded, and if a character vector, it is collapsed into a single string before being sent to the queue.
visibility_timeoutOptional visibility timeout after being read, in seconds. The default is 30 seconds.
time_to_liveOptional message time-to-live, in seconds. The default is 7 days.
Returns
The message text, invisibly.
Method update_message()
Updates a message in the queue. This requires that the message object must include a pop receipt, which is present if it was obtained by means other than peeking.
This operation can be used to continually extend the invisibility of a queue message. This functionality can be useful if you want a worker role to "lease" a message. For example, if a worker role calls get_messages and recognizes that it needs more time to process a message, it can continually extend the message's invisibility until it is processed. If the worker role were to fail during processing, eventually the message would become visible again and another worker role could process it.
Usage
StorageQueue$update_message(msg, visibility_timeout, text = msg$text)
Arguments
msgA message object, of class
QueueMessage.visibility_timeoutThe new visibility timeout (time to when the message will again be visible).
textOptionally, new message text, either a raw or character vector. If a raw vector, it is base64-encoded, and if a character vector, it is collapsed into a single string before being sent to the queue.
Returns
The message object, invisibly.
Method delete_message()
Deletes a message from the queue. This requires that the message object must include a pop receipt, which is present if it was obtained by means other than peeking.
Usage
StorageQueue$delete_message(msg)
Arguments
msgA message object, of class
QueueMessage.
Method print()
Print method for this class.
Usage
StorageQueue$print(...)
Arguments
...Not currently used.
Method clone()
The objects of this class are cloneable with this method.
Usage
StorageQueue$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
Examples
## Not run:
endp <- storage_endpoint("https://mystorage.queue.core.windows.net", key="key")
# to talk to an existing queue
queue <- storage_queue(endp, "queue1")
# to create a new queue
queue2 <- create_storage_queue(endp, "queue2")
# various ways to delete a queue (will ask for confirmation first)
queue2$delete()
delete_storage_queue(queue2)
delete_storage_queue(endp, "queue2")
# to get all queues in this storage account
queue_lst <- list_storage_queues(endp)
# working with a queue: put, get, update and delete messages
queue$put_message("new message")
msg <- queue$get_message()
msg$update(visibility_timeout=60, text="updated message")
queue$delete_message(msg)
# delete_message simply calls the message's delete() method, so this is equivalent
msg$delete()
# retrieving multiple messages at a time (up to 32)
msgs <- queue$get_messages(30)
# deleting is still per-message
lapply(msgs, function(m) m$delete())
# you can use the process pool from AzureRMR to do this in parallel
AzureRMR::init_pool()
AzureRMR::pool_lapply(msgs, function(m) m$delete())
AzureRMR::delete_pool()
## End(Not run)