简体   繁体   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

I want an azure app-function that would be triggered when a new blob is added into the specified container in a storage account and transfer that blob to a specified database and container in Azure CosmosDB. 我希望将新的Blob添加到存储帐户中的指定容器中并将该Blob传输到Azure CosmosDB中的指定数据库和容器时触发的azure应用程序功能。 I created an app-function and specified the storage account and container that has to be monitored. 我创建了一个应用程序功能,并指定了必须监视的存储帐户和容器。 In the output binding, I selected Azure CosmosDB as my output binding from portal and specified the details of the CosmosDb account that I had. 在输出绑定中,我选择Azure CosmosDB作为门户的输出绑定,并指定了我拥有的CosmosDb帐户的详细信息。 I tried executing it, but it said 我尝试执行它,但是它说

The specified container does not exist

I couldn't understand which container the error was about so I ticked the If true, creates the Azure Cosmos DB database and collection option for the CosmosDB. 我无法理解错误所在的容器,因此勾选了“ 如果为真”,则为CosmosDB 创建Azure Cosmos DB数据库和收集选项。 It didn't make any difference. 没什么区别。 So I switched to the Advanced Editor to check the function.json, there I found the Output binding type to by "cosmosDB" and a warning green underline under it which stated 因此,我切换到高级编辑器以检查f​​unction.json,在其中找到“ cosmosDB”的“输出”绑定类型,并在其下显示绿色警告下划线,指出

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

I changed "cosmosDB" to "documentDB" and tried executing it again. 我将“ cosmosDB”更改为“ documentDB”,并尝试再次执行它。 This time there was a popup stating 这次有一个弹出窗口指出

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

I followed https://docs.microsoft.com/en-us/azure/azure-functions/install-update-binding-extensions-manual to add an extension and I added the following extension 我遵循https://docs.microsoft.com/zh-cn/azure/azure-functions/install-update-binding-extensions-manual添加扩展名,并添加了以下扩展名

Microsoft.Azure.WebJobs.Extensions.DocumentDB Version 1.3.0

After that, I again executed the app-function and it again shows mye the same popup regarding documentDB not registered and if I change back the documentDB to cosmosDb in the advanced editor it again says that the container does not exist. 在那之后,我再次执行了app-function,并且再次向我显示了有关未注册documentDB的弹出窗口,如果我在高级编辑器中将documentDB改回为cosmosDb,它再次表示该容器不存在。 Could someone please pointout where I am going wrong. 有人可以指出我要去哪里了。

Update : 更新:

@Jack Jia Yes, I had followed the same procedure you said. @杰克·贾(Jack Jia)是的,我按照您说的相同步骤进行。 In order to re-esure, I retried the process which again gave me the same result. 为了确保安全,我重试了该过程,该过程再次给了我相同的结果。 But during this process I realized another issue I had faced. 但是在此过程中,我意识到自己遇到的另一个问题。 When I was creating the function app, initially it said Deployment failed with 当我创建功能应用程序时,最初说部署失败,

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

But after a while I found the function app I created in my all resources tab and I continued. 但是过了一会儿,我在所有资源选项卡中找到了我创建的功能应用程序,然后继续。 Maybe thats the reason I am encountering such a issue. 也许这就是我遇到这样一个问题的原因。 But for creating the function app I had refered https://docs.microsoft.com/en-au/learn/modules/chain-azure-functions-data-using-bindings/3-explore-input-and-output-binding-types-portal-lab which clearly states that central india is a valid sandbox location. 但是对于创建功能应用程序,我已经参考了https://docs.microsoft.com/zh-cn/learn/modules/chain-azure-functions-data-using-bindings/3-explore-input-and-output-binding -types-portal-lab明确指出印度中部是有效的沙箱位置。 It would be great if you could guide me here. 如果您能在这里指导我,那就太好了。

Just tested (with CosmosDB SQL API), and got a success. 刚刚测试(使用CosmosDB SQL API),并获得了成功。 Could you please have a further check with the integrate settings? 您能否进一步检查集成设置?

You can get the database name and collection name from the overview of your CosmosDB: 您可以从CosmosDB的概述中获取数据库名称和集合名称:

在此处输入图片说明

And set the right values in function app: 并在功能应用中设置正确的值:

在此处输入图片说明

The function code: 功能代码:

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 };
}

Every time I uploaded a file to the target blob container, a new document would be add to the cosmos DB. 每次我将文件上传到目标Blob容器时,都会将一个新文档添加到cosmos DB中。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM