2017-02-17 46 views
1

我给一个天青功能情形:天青功能应用程序:无法绑定队列为类型 'Microsoft.WindowsAzure.Storage.Queue.CloudQueue'(的IBinder)

  1. HTTP触发。
  2. 基于我想读从适当的存储队列中的消息和数据返回HTTP参数。

下面是函数的代码(F#):

let Run(request: string, customerId: int, userName: string, binder: IBinder) = 
    let subscriberKey = sprintf "%i-%s" customerId userName 
    let attribute = new QueueAttribute(subscriberKey) 
    let queue = binder.Bind<CloudQueue>(attribute)  
    () //TODO: read messages from the queue 

编译会成功(适当的NuGet引用开放包),但我得到的运行时异常:

Microsoft.Azure.WebJobs.Host: 
Can't bind Queue to type 'Microsoft.WindowsAzure.Storage.Queue.CloudQueue'. 

我的代码是基于从this article一个例子。

我在做什么错?

更新:现在我知道我没有指定连接名称的任何地方。我需要对基于IBinder的队列访问进行绑定吗?

更新2:我function.json文件:

{ 
    "bindings": [ 
    { 
     "type": "httpTrigger", 
     "name": "request", 
     "route": "retrieve/{customerId}/{userName}", 
     "authLevel": "function", 
     "methods": [ 
     "get" 
     ], 
     "direction": "in" 
    } 
], 
"disabled": false 
} 

回答

3

我怀疑你遇到版本问题,因为你带来一个冲突版本存储SDK的。相反,使用内置的(不带任何nuget软件包)。此代码的工作,没有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 

这将绑定到默认存储账号(我们为您创建功能应用程序创建时的一个)。如果你想点到不同的存储帐户,您需要创建一个阵列属性的,并且包括StorageAccountAttribute指向你所需的存储帐户(例如new StorageAccountAttribute("your_storage"))。然后,通过这个阵列的属性(与队列属性第一阵列中)插入过载BindAsync接受一个属性阵列。有关更多详细信息,请参阅here

但是,如果你不需要做任何复杂的解析/格式化来形成队列名称,我认为你甚至不需要使用活页夹来做这个。您可以完全声明式地绑定到队列。这里的function.json和代码:

{ 
    "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" 
    } 
    ] 
} 

而且功能代码:

#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 
+0

当我试图删除的NuGet引用我'无法加载文件或程序集“Microsoft.WindowsAzure.Storage,版本= 8.0.1.0文化=中性公钥= 31bf3856ad364e35' 或它的一个依赖。定位的程序集清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040).' – Mikhail

+0

基于https://docs.microsoft.com/zh-cn/azure/azure-functions/functions-bindings-storage-queue我认为输入绑定不支持队列..谢谢,我会尽力的! – Mikhail

+0

我试着复制粘贴你的第二个代码,但是Portal给我错误,找不到'Microsoft.WindowsAzure.Storage',然后'我们无法访问你的函数应用程序(未找到)。请稍后再试'。 – Mikhail