Azure Queue Storage
Â
Intro
Â
Documentation
Â
Tips and Tidbits
Azure Queue Storage is a service for storing large numbers of messages.
You access messages from anywhere in the world via authenticated calls using HTTP or HTTPS.
A queue message can be up to 64 KB in size.
A queue may contain millions of messages, up to the total capacity limit of a storage account.
Queues are commonly used to create a backlog of work to process asynchronously
All access is done through a storage account.
Queues are addressable using the URL format
https://<storage account>.queue.core.windows.net/<queue>
.A message, in any format, of up to 64 KB.
The maximum time-to-live can be any positive number, or -1 indicating that the message doesn't expire.
If this parameter is omitted, the default time-to-live is seven days.
Â
Â
Storage queues and Service Bus queues - compared and contrasted
Storage queues and Service Bus queues - compared and contrasted
Use ASB is FIFO is a requirement.
Use Storage Qeues if queue size > 80GB
Â
Create and manage Azure Queue Storage queues and messages by using .NET
Â
Create and manage Azure Queue Storage queues and messages by using .NET
The
QueueClient
class enables you to retrieve queues stored in Queue storageQueueClient queueClient = new QueueClient(connectionString, queueName);
Â
create a queue if it does not already exist:
// Get the connection string from app settings string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"]; // Instantiate a QueueClient which will be used to create and manipulate the queue QueueClient queueClient = new QueueClient(connectionString, queueName); // Create the queue queueClient.CreateIfNotExists();
Â
To insert a message into an existing queue, call the
SendMessage
method. A message can be either a string (in UTF-8 format) or a byte array.if (queueClient.Exists()) { // Send a message to the queue queueClient.SendMessage(message); }
Â
You can peek at the messages in the queue without removing them from the queue by calling the
PeekMessages
method.If you don't pass a value for the
maxMessages
parameter, the default is to peek at one message.
Â
You can change the contents of a message in-place in the queue.
If the message represents a work task, you could use this feature to update the status of the work task.
The following code updates the queue message with new contents, and sets the visibility timeout to extend another 60 seconds.
This saves the state of work associated with the message, and gives the client another minute to continue working on the message.
Â
Dequeue a message from a queue in two steps.
When you call
ReceiveMessages
, you get the next message in a queue.A message returned from
ReceiveMessages
becomes invisible to any other code reading messages from this queue.By default, this message stays invisible for 30 seconds.
To finish removing the message from the queue, you must also call
DeleteMessage
.
This two-step process of removing a message assures that if your code fails to process a message due to hardware or software failure, another instance of your code can get the same message and try again.
Your code calls
DeleteMessage
right after the message has been processed.
Â
The
GetProperties
method returns queue properties including the message count.The
ApproximateMessagesCount
property contains the approximate number of messages in the queue.This number is not lower than the actual number of messages in the queue, but could be higher.