I suspect that you're having versioning issues because you're bringing in a conflicting version of the Storage SDK. Instead, use the built in one (w/o bringing in any nuget packages). This code works with no project.json:
#r "Microsoft.WindowsAzure.Storage"
open Microsoft.Azure.WebJobs;
open Microsoft.WindowsAzure.Storage.Queue;
let Run(request: string, customerId: int, userName: string, binder: IBinder) =
async {
let subscriberKey = sprintf "%i-%s" customerId userName
let attribute = new QueueAttribute(subscriberKey)
let! queue = binder.BindAsync<CloudQueue>(attribute) |> Async.AwaitTask
() //TODO: read messages from the queue
} |> Async.RunSynchronously
This will bind to the default storage account (the one we created for you when your Function App was created). If you want to point to a different storage account, you'll need to create an array of attributes, and include a StorageAccountAttribute
that points to your desired storage account (e.g. new StorageAccountAttribute("your_storage")
). You then pass this array of attributes (with the queue attribute first in the array) into the BindAsync
overload that takes an attribute array. See here for more details.
However, if you don't need to do any sophisticated parsing/formatting to form the queue name, I don't think you even need to use Binder for this. You can bind to the queue completely declaratively. Here's the function.json and code:
{
"bindings": [
{
"type": "httpTrigger",
"name": "request",
"route": "retrieve/{customerId}/{userName}",
"authLevel": "function",
"methods": [
"get"
],
"direction": "in"
},
{
"type": "queue",
"name": "queue",
"queueName": "{customerId}-{userName}",
"connection": "<your_storage>",
"direction": "in"
}
]
}
And the function code:
#r "Microsoft.WindowsAzure.Storage"
open Microsoft.Azure.WebJobs;
open Microsoft.WindowsAzure.Storage.Queue;
let Run(request: string, queue: CloudQueue) =
async {
() //TODO: read messages from the queue
} |> Async.RunSynchronously
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…