Azure Message Queue Manipulation with PowerShell

New to Message queues in Azure? Here’s some samples for working with them.

#Azure Message Queue Manipulation

$StorageAccountName = "storage001"
$StorageAccountKey = Get-AzureRMStorageAccountKey -StorageAccountName $StorageAccountName -ResourceGroupName "Storage"
$storeAuthContext = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey[0].value

# Create Queue
$myQueue = New-AzureStorageQueue -Name 'myqueue' -Context $storeAuthContext

# Create Queue Message	
$queueMessage = New-Object -TypeName Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage -ArgumentList 'Hello'
#Can run next line a few times in a row to fill queue with data

# Get Queue Message  (gets oldest message in queue and takes it out of queue)

#Get-AzureStorageQueue will retrieve general information about the storage queue including approximate message count. 

##PartitionKey, RowKey and TimeStamp required properties.  TimeStamp is created automatically.

## Some C# Commands
// Retrieve a reference to a queue
CloudQueue queue = queueClient.GetQueueReference("myqueue");

// Peek at the next message
CloudQueueMessage peekedMessage = queue.PeekMessage();

// Display message.

// Create a message and add it to the queue.
CloudQueueMessage message = new CloudQueueMessage("Hello, World");

// Fetch the queue attributes.

// Retrieve the cached approximate message count.
int? cachedMessageCount = queue.ApproximateMessageCount;

// Display number of messages.
Console.WriteLine("Number of messages in queue: " + cachedMessageCount);

// Delete the queue.

Leave a Reply

Your email address will not be published. Required fields are marked *