Azure Storage Type Provider


Working with Queues

For more information on Queues in general, please see some of the many articles on MSDN or the Azure documentation. Some of the core features of the Queue provider are: -

Rapid navigation

You can easily move between queues and view key information on that queue. Simply dotting into a queue will automatically request the latest details on the queue. This allows easy exploration of your queue assets, directly from within the REPL.

1: 
2: 
let queue = Azure.Queues.``sample-queue``
printfn "Queue '%s' has %d items on it." queue.Name (queue.GetCurrentLength())
Queue 'sample-queue' has 0 items on it.

Processing messages

It is easy to push and pop messages onto / off a queue - simply call the Enqueue() and Dequeue() methods on the appropriate queue. Enqueue will return an option message, in case there is nothing on the queue. Once you have finished processing the message, simply call Delete().

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
async {
    printfn "Queue length is %d." (queue.GetCurrentLength())

    // Put a message on the queue
    printfn "Enqueuing a message!"
    do! queue.Enqueue("Hello from Azure Type Provider")
    printfn "Queue length is %d." (queue.GetCurrentLength())

    // Get the message back off the queue
    let dequeuedMessage = (queue.Dequeue() |> Async.RunSynchronously).Value // don't try this at home :)
    printfn "%A" dequeuedMessage
    
    // Delete it off the queue to tell Azure we're done with it.
    printfn "Deleting the message."
    do! queue.DeleteMessage dequeuedMessage.Id
    printfn "Queue length is %d." (queue.GetCurrentLength())
} |> Async.RunSynchronously
Queue length is 0.
Enqueuing a message!
Queue length is 1.
{Id =
  ProvidedMessageId
    (MessageId "c0dec0d8-c2dc-4cb1-8ea9-76c2814a050d",
     PopReceipt "sFs0Ccrr1AgBAAAA");
 DequeueCount = 1;
 InsertionTime = Some 25/08/2017 15:00:03 +00:00;
 ExpirationTime = Some 01/09/2017 15:00:03 +00:00;
 NextVisibleTime = Some 25/08/2017 15:00:33 +00:00;
 AsBytes = Value is not created.;
 AsString = Value is not created.;}
Deleting the message.
Queue length is 0.

Modifying Queues

You can easily modify the contents of an existing message and push it back onto the queue, or clear the queue entirely. Note that the properties to access the payload (AsString and AsBytes) are lazily evaluated and as such are exposed as Lazy.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
let printMessage msg =
    printfn "Message %A with body '%s' has been dequeued %d times." msg.Id msg.AsString.Value msg.DequeueCount

async {
    printfn "Enqueuing a message!"
    do! queue.Enqueue("Hello from Azure Type Provider")
    
    // Get the message, then put it back on the queue with a new payload immediately.
    printfn "Dequeuing it."
    let! message = queue.Dequeue()
    match message with
    | Some message ->
        printMessage message
        printfn "Updating it and dequeuing it again."
        do! queue.UpdateMessage(message.Id, "Goodbye from Azure Type Provider")
        
        // Now dequeue the message again and interrogate it
        let! message = queue.Dequeue()
        match message with
        | Some message ->
            printMessage message
            do! queue.DeleteMessage message.Id
        | None -> ()
    | None -> ()
} |> Async.RunSynchronously
Enqueuing a message!
Dequeuing it.
Message ProvidedMessageId
  (MessageId "644a094a-832c-4d6d-9934-42029eac0402",
   PopReceipt "EDhhCcrr1AgBAAAA") with body 'Hello from Azure Type Provider' has been dequeued 1 times.
Updating it and dequeuing it again.
Message ProvidedMessageId
  (MessageId "644a094a-832c-4d6d-9934-42029eac0402",
   PopReceipt "4GhvCcrr1AgCAAAA") with body 'Goodbye from Azure Type Provider' has been dequeued 2 times.

Shared Access Signature generation

The type provider exposes a simple method for generating time-dependant SAS codes for queues. Omit permissions parameter to get full-access SAS token.

1: 
2: 
3: 
4: 
5: 
let duration = TimeSpan.FromMinutes 37.
printfn "Current time: %O" DateTime.UtcNow
printfn "SAS expiry: %O" (DateTime.UtcNow.Add duration)
let sasCode = queue.GenerateSharedAccessSignature(duration, permissions = (QueuePermission.Peek ||| QueuePermission.Enqueue ||| QueuePermission.DequeueAndDeleteMessageAndClear)) 
printfn "SAS URI: %O" sasCode
Current time: 25/08/2017 15:00:04
SAS expiry: 25/08/2017 15:37:04
SAS URI: ?sv=2015-12-11&sig=MnX78bnW8U9zKuLCsV4H1s4QiBCsJxbrqVUz2zpbbeA%3D&se=2017-08-25T15%3A37%3A04Z&sp=rap

Peeking the queue

The Queue Provider allows you to preview messages on the queue directly in intellisense. Simply dot into the "Peek" property on the queue, and the first 32 messages on the queue will appear. Properties on them can be bound with their values.

Fork me on GitHub