我有一个Azure功能,我在Azure门户中创建,现在想要使用与VS2017预览相关的visual studio azure工具重新创建它。
我的功能是定时器触发,还有Azure DocumentDB的输入绑定(带有查询)和绑定到Azure Service Bus队列的输出。
以下是门户网站的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中,我使用TimerTriggered模板创建Azure Function项目,然后创建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配置文件中连接它。
答案 0 :(得分:4)
using Microsoft.Azure.WebJobs
更新documentDb参数,如下所示(也添加其他属性)
[DocumentDB(ConnectionStringSetting = "")]IEnumerable<dynamic> incomingDocuments
更新serviceBus参数,如下所示
[ServiceBus("test-output-requests",Connection = "ConnectionValue")]
验证bin/functionName/function.json
谢谢,
那仁