gpt4 book ai didi

c# - Azure Functions 使用输入和输出绑定(bind)进行本地开发

转载 作者:太空狗 更新时间:2023-10-30 01:00:23 24 4
gpt4 key购买 nike

查看在 Visual Studio 2017 中开发 Azure Functions 的示例,可以看到可以使用触发器设置新的函数模板。

因此对于队列,模板如下:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionApp1
{
public static class Function1
{
[FunctionName("QueueTriggerCSharp")]
public static void Run([QueueTrigger("myqueue-items", Connection = "QueueStorage")]string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
}
}

您是否能够在本地添加并运行其他输入和输出绑定(bind),例如:

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionApp1
{
public static class Function1
{
[FunctionName("QueueTriggerCSharp")]
public static async Task Run([QueueTrigger("myqueue-items", Connection = "QueueStorage")]string myQueueItem, CloudTable inputTable, IAsyncCollector<string> outputEventHubMessages, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");

TableQuery<TableEntity> query = new TableQuery<FailedEventEntity>().Where(
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "helloWorld"));

List<TableEntity> entities = inputTable.ExecuteQuery(query).ToList();

await outputEventHubMessages.AddAsync(myQueueItem);

}
}
}

是否需要在 local.settings.json 中进行配置?

最佳答案

当然是你。您还需要用属性来装饰它们:

[Table("table-name")] CloudTable inputTable, 
[EventHub("event-hub-name")] IAsyncCollector<string> outputEventHubMessages

本地环境的配置值实际上将从 local.settings.json 中获取,因此您需要将它们添加到那里(连接字符串等)。

关于c# - Azure Functions 使用输入和输出绑定(bind)进行本地开发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46687921/

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