簡體   English   中英

每當將Blob添加到容器中時,從Blob存儲向CosmosDB發送數據時,Azure App-Function綁定類型的問題

[英]Problem with the binding type of azure app-function when sending data from blob storage to cosmosDB whenever a blob is added into a container

我希望將新的Blob添加到存儲帳戶中的指定容器中並將該Blob傳輸到Azure CosmosDB中的指定數據庫和容器時觸發的azure應用程序功能。 我創建了一個應用程序功能,並指定了必須監視的存儲帳戶和容器。 在輸出綁定中,我選擇Azure CosmosDB作為門戶的輸出綁定,並指定了我擁有的CosmosDb帳戶的詳細信息。 我嘗試執行它,但是它說

The specified container does not exist

我無法理解錯誤所在的容器,因此勾選了“ 如果為真”,則為CosmosDB 創建Azure Cosmos DB數據庫和收集選項。 沒什么區別。 因此,我切換到高級編輯器以檢查f​​unction.json,在其中找到“ cosmosDB”的“輸出”綁定類型,並在其下顯示綠色警告下划線,指出

Value is not accepted. Valid values: ["documentDB"]

我將“ cosmosDB”更改為“ documentDB”,並嘗試再次執行它。 這次有一個彈出窗口指出

Function (BlobTrigger) Error: The binding type(s) 'documentDB' are not registered. Please ensure the type is correct and the binding extension is installed.
Session Id: 10d62e7e360544009389504620f3506e

Timestamp: 2019-07-24T04:14:08.601Z

我遵循https://docs.microsoft.com/zh-cn/azure/azure-functions/install-update-binding-extensions-manual添加擴展名,並添加了以下擴展名

Microsoft.Azure.WebJobs.Extensions.DocumentDB Version 1.3.0

在那之后,我再次執行了app-function,並且再次向我顯示了有關未注冊documentDB的彈出窗口,如果我在高級編輯器中將documentDB改回為cosmosDb,它再次表示該容器不存在。 有人可以指出我要去哪里了。

更新:

@傑克·賈(Jack Jia)是的,我按照您說的相同步驟進行。 為了確保安全,我重試了該過程,該過程再次給了我相同的結果。 但是在此過程中,我意識到自己遇到的另一個問題。 當我創建功能應用程序時,最初說部署失敗,

{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"Unauthorized","message":"{\r\n \"Code\": \"Unauthorized\",\r\n \"Message\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\",\r\n \"Target\": null,\r\n \"Details\": [\r\n {\r\n \"Message\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\"\r\n },\r\n {\r\n \"Code\": \"Unauthorized\"\r\n },\r\n {\r\n \"ErrorEntity\": {\r\n \"ExtendedCode\": \"52020\",\r\n \"MessageTemplate\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\",\r\n \"Parameters\": [\r\n \"default\"\r\n ],\r\n \"Code\": \"Unauthorized\",\r\n \"Message\": \"The scale operation is not allowed for this subscription in this region. Try selecting different region or scale option.\"\r\n }\r\n }\r\n ],\r\n \"Innererror\": null\r\n}"}]}

但是過了一會兒,我在所有資源選項卡中找到了我創建的功能應用程序,然后繼續。 也許這就是我遇到這樣一個問題的原因。 但是對於創建功能應用程序,我已經參考了https://docs.microsoft.com/zh-cn/learn/modules/chain-azure-functions-data-using-bindings/3-explore-input-and-output-binding -types-portal-lab明確指出印度中部是有效的沙箱位置。 如果您能在這里指導我,那就太好了。

剛剛測試(使用CosmosDB SQL API),並獲得了成功。 您能否進一步檢查集成設置?

您可以從CosmosDB的概述中獲取數據庫名稱和集合名稱:

在此處輸入圖片說明

並在功能應用中設置正確的值:

在此處輸入圖片說明

功能代碼:

public static void Run(Stream myBlob, string name, out dynamic outputDocument, ILogger log)
{
    log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
    outputDocument = new { datainfo = name, id = Guid.NewGuid(), contentLength = myBlob.Length };
}

每次我將文件上傳到目標Blob容器時,都會將一個新文檔添加到cosmos DB中。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM