如何将 DocumentDB 输入绑定到 Azure 函数?
How to bind DocumentDB input to Azure Function?
我有一个在 Azure 门户中创建的 Azure 函数,现在我想使用与 VS2017 预览版关联的 visual studio azure 工具重新创建它。
我的函数是定时器触发的,还有一个 Azure DocumentDB 的输入绑定(带查询)和一个到 Azure 服务总线队列的输出绑定。
这是来自门户的 functions.json
定义:
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"type": "serviceBus",
"name": "outputQueue",
"queueName": "test-output-requests",
"connection": "send-refresh-request",
"accessRights_": "Send",
"direction": "out"
},
{
"type": "documentDB",
"name": "incomingDocuments",
"databaseName": "test-db-dev",
"collectionName": "TestingCollection",
"sqlQuery": "select * from c where c.docType = \"Test\"",
"connection": "my-testing_DOCUMENTDB",
"direction": "in"
}
],
"disabled": false
}
在 VS2017 中,我创建了一个 Azure Function 项目,然后使用 TimerTriggered 模板创建了一个 Azure 函数:
public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log, ICollector<dynamic> outputQueue, IEnumerable<dynamic> incomingDocuments)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
//Inspect incomingDocuments .. push messages to outputQueue
}
运行 在本地,计时器按预期触发 - 但如何在代码中重新创建输入和输出绑定?我不确定我应该使用什么属性,以及我在 json 配置文件中需要什么来连接它。
- 添加对以下 nuget 包的引用
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.DocumentDB/
- 添加
using Microsoft.Azure.WebJobs
如下更新 documentDb 参数(同时添加其他属性)
[DocumentDB(ConnectionStringSetting = "")]IEnumerable<dynamic> incomingDocuments
更新serviceBus参数如下
[ServiceBus("test-output-requests",Connection = "ConnectionValue")]
在bin/functionName/function.json
中验证生成的function.json
谢谢,
那仁
我有一个在 Azure 门户中创建的 Azure 函数,现在我想使用与 VS2017 预览版关联的 visual studio azure 工具重新创建它。
我的函数是定时器触发的,还有一个 Azure DocumentDB 的输入绑定(带查询)和一个到 Azure 服务总线队列的输出绑定。
这是来自门户的 functions.json
定义:
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"type": "serviceBus",
"name": "outputQueue",
"queueName": "test-output-requests",
"connection": "send-refresh-request",
"accessRights_": "Send",
"direction": "out"
},
{
"type": "documentDB",
"name": "incomingDocuments",
"databaseName": "test-db-dev",
"collectionName": "TestingCollection",
"sqlQuery": "select * from c where c.docType = \"Test\"",
"connection": "my-testing_DOCUMENTDB",
"direction": "in"
}
],
"disabled": false
}
在 VS2017 中,我创建了一个 Azure Function 项目,然后使用 TimerTriggered 模板创建了一个 Azure 函数:
public static void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, TraceWriter log, ICollector<dynamic> outputQueue, IEnumerable<dynamic> incomingDocuments)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
//Inspect incomingDocuments .. push messages to outputQueue
}
运行 在本地,计时器按预期触发 - 但如何在代码中重新创建输入和输出绑定?我不确定我应该使用什么属性,以及我在 json 配置文件中需要什么来连接它。
- 添加对以下 nuget 包的引用 https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.DocumentDB/
- 添加
using Microsoft.Azure.WebJobs
如下更新 documentDb 参数(同时添加其他属性)
[DocumentDB(ConnectionStringSetting = "")]IEnumerable<dynamic> incomingDocuments
更新serviceBus参数如下
[ServiceBus("test-output-requests",Connection = "ConnectionValue")]
在bin/functionName/function.json
谢谢,
那仁