gpt4 book ai didi

使用 local.settings.json 的 Azure 函数 cosmos db 输出

转载 作者:行者123 更新时间:2023-12-02 00:40:11 27 4
gpt4 key购买 nike

查看有关 azure 函数的文档,特别是 this one 。如何通过门户设置集成非常清楚,但本地开发却非常模糊。

我的代码结构如下:

[FunctionName("foobar")]
public static void Run([QueueTrigger("foo")]Foo myQueueItem, out object dbFoo)
{
//do cool stuff here
}

队列触发器与 Azure 存储模拟器配合得很好,但没有关于如何设置 local.settings.json 的说明。通过 Visual Studio 自动生成的文件如下所示:

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": ""
}
}

cosmos db 的连接信息位于此结构中的什么位置以使函数能够正确运行?

最佳答案

它应该看起来像这样:

public static void Run(
[QueueTrigger("foo")] Foo myQueueItem,
[DocumentDB("MyDB", "MyCollection", ConnectionStringSetting = "MyConnectionString")]
out object dbFoo)

配置为:

{
"IsEncrypted": false,
"Values": {
"MyConnectionString": "...your cosmos db string..."
}
}

在 Azure 中,您必须将 MyConnectionString 参数放入应用程序设置。

更新:在 Functions 的 V2 版本中,DocumentDB 绑定(bind)属性已替换为 CosmosDB 属性,请参阅 docs .

关于使用 local.settings.json 的 Azure 函数 cosmos db 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47285249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com