具有 CosmosDB 输入的时间触发器功能
Time trigger function with CosmosDB inputs
我在 azure functions 中创建了一个时间触发函数,并添加了一个 CosmosDB 输入,如下所示。
下面是.csx文件
#r "Microsoft.Azure.Documents.Client"
using System;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
public static async Task Run(TimerInfo myTimer, string[] inputDocument, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
// string [] = bindings.inputDocument;
DocumentClient client;
}
如何将 cosmosDb 中的输入文档导入到这个 csx 文件中?
我不熟悉C#,在javascript中我们将使用var Data = context.bindings.DataInput;
如何在 C# 中做同样的事情?
您可以像下面的代码片段一样使用它
public static void Run(TimerInfo myTimer, IEnumerable<dynamic> documents)
{
foreach (var doc in documents)
{
// operate on each document
}
}
中有更多示例
评论中的问题
If we have more than one cosmos Db input do we need to add as below ?
否,即使您有多个输入,也会使用 IEnumerable<dynamic> documents
。你可以迭代列表。
How to add if we have a cosmosDB output ?
此处使用 out object
指向您的绑定。
public static void Run(string myQueueItem, out object employeeDocument, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
dynamic employee = JObject.Parse(myQueueItem);
employeeDocument = new {
id = employee.name + "-" + employee.employeeId,
name = employee.name,
employeeId = employee.employeeId,
address = employee.address
};
}
有关 Output
的更多信息
我在 azure functions 中创建了一个时间触发函数,并添加了一个 CosmosDB 输入,如下所示。
下面是.csx文件
#r "Microsoft.Azure.Documents.Client"
using System;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
public static async Task Run(TimerInfo myTimer, string[] inputDocument, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
// string [] = bindings.inputDocument;
DocumentClient client;
}
如何将 cosmosDb 中的输入文档导入到这个 csx 文件中?
我不熟悉C#,在javascript中我们将使用var Data = context.bindings.DataInput;
如何在 C# 中做同样的事情?
您可以像下面的代码片段一样使用它
public static void Run(TimerInfo myTimer, IEnumerable<dynamic> documents)
{
foreach (var doc in documents)
{
// operate on each document
}
}
中有更多示例
评论中的问题
If we have more than one cosmos Db input do we need to add as below ?
否,即使您有多个输入,也会使用 IEnumerable<dynamic> documents
。你可以迭代列表。
How to add if we have a cosmosDB output ?
此处使用 out object
指向您的绑定。
public static void Run(string myQueueItem, out object employeeDocument, ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
dynamic employee = JObject.Parse(myQueueItem);
employeeDocument = new {
id = employee.name + "-" + employee.employeeId,
name = employee.name,
employeeId = employee.employeeId,
address = employee.address
};
}
有关 Output
的更多信息