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 "44963d2f-b6be-4889-bb5a-924d67552b9c",
     PopReceipt "8Jui8WEn1QgBAAAA");
 DequeueCount = 1;
 InsertionTime = Some 09/11/2017 11:06:06 +00:00;
 ExpirationTime = Some 16/11/2017 11:06:06 +00:00;
 NextVisibleTime = Some 09/11/2017 11:06:36 +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 "1a445322-c30a-445a-ae72-2e1fd1d7942c",
   PopReceipt "AETM8WEn1QgBAAAA") with body 'Hello from Azure Type Provider' has been dequeued 1 times.
Updating it and dequeuing it again.
Message ProvidedMessageId
  (MessageId "1a445322-c30a-445a-ae72-2e1fd1d7942c",
   PopReceipt "MO7Y8WEn1QgCAAAA") 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: 09/11/2017 11:06:06
SAS expiry: 09/11/2017 11:43:06
SAS URI: ?sv=2015-12-11&sig=xPXeuTlyZl6HjqY92Lqx%2B7h44wEjXHgBmhq%2BVPH5FUM%3D&se=2017-11-09T11%3A43%3A06Z&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. This is particularly useful when using the hot schema loading feature of the type provider.

Fork me on GitHub