2017-02-17 45 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