基于计时器的Azure功能,具有表存储、HTTP请求和Azure服务总线

基于计时器的Azure功能,具有表存储、HTTP请求和Azure服务总线,azure,azure-functions,azure-table-storage,azure-servicebus-topics,Azure,Azure Functions,Azure Table Storage,Azure Servicebus Topics,我现在在一个控制台应用程序中编写了一个进程,它启动一个计划任务,从Azure表存储中读取数据,并基于该数据,向我们使用的第三方供应商进行API调用,反序列化响应数据,在结果中循环数组,将循环的各个迭代保存到Azure表存储中的不同表中,然后将循环的每个迭代的消息发布到Azure service bus,这些消息由另一个客户端使用 为了让更多的任务进入云中,我做了一些研究,似乎Azure函数是替代我的控制台应用程序的一个很好的候选。我在VisualStudio2019中启动了一个新的Azure函数

我现在在一个控制台应用程序中编写了一个进程,它启动一个计划任务,从Azure表存储中读取数据,并基于该数据,向我们使用的第三方供应商进行API调用,反序列化响应数据,在结果中循环数组,将循环的各个迭代保存到Azure表存储中的不同表中,然后将循环的每个迭代的消息发布到Azure service bus,这些消息由另一个客户端使用

为了让更多的任务进入云中,我做了一些研究,似乎Azure函数是替代我的控制台应用程序的一个很好的候选。我在VisualStudio2019中启动了一个新的Azure函数项目,作为一个计时器函数,然后投入到一些阅读中,我很快就迷失了方向

我所做的阅读讨论了在我的Run方法参数中使用绑定,这些参数带有连接字符串等的属性,但我不确定这是我应该走的方向。听起来这会使我的表存储的身份验证变得更容易,但我不知道如何使用这些钩子来查询我的表,然后执行插入。我甚至还没有接触到服务总线的东西,也没有考虑过对我们的第三方供应商的api进行HTTP调用

我知道这是一个非常宽泛的问题,我没有任何代码可以发布,因为我甚至很难用它走出起点。MS文档到处都是,我找不到任何特定于我的需求的东西,我保证我已经花了相当多的时间尝试了

Azure功能是否是我应该走的正确道路?如果没有,还有什么其他选择


TIA

您应该使用Azure功能和时间触发器来替换您的控制台应用程序

可用于输入/输出的绑定可以帮助您保存一些代码行,例如:

而不是使用以下代码将数据插入azure表:

// Retrieve storage account information from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

// Create a table client for interacting with the table service
CloudTableClient tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());

// Create a table client for interacting with the table service 
CloudTable table = tableClient.GetTableReference("MyTable");

//some code to populate an entity
var entity = new { PartitionKey = "Http", RowKey = Guid.NewGuid().ToString(), Text = input.Text };

// Create the InsertOrReplace table operation
TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity);

// Execute the operation.
TableResult result = await table.ExecuteAsync(insertOrMergeOperation);
您可以使用:

[FunctionName("TableOutput")]
[return: Table("MyTable")]
public static MyPoco TableOutput([HttpTrigger] dynamic input, ILogger log)
{
    log.LogInformation($"C# http trigger function processed: {input.Text}");
    return new MyPoco { PartitionKey = "Http", RowKey = Guid.NewGuid().ToString(), Text = input.Text };
}
PS:前面代码中的输入触发器是HTTP触发器,但只是解释如何使用输出绑定

您可以在此处找到更多信息:


你应该注意:

你应该使用Azure函数和时间触发器来替换你的控制台应用程序

可用于输入/输出的绑定可以帮助您保存一些代码行,例如:

而不是使用以下代码将数据插入azure表:

// Retrieve storage account information from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

// Create a table client for interacting with the table service
CloudTableClient tableClient = storageAccount.CreateCloudTableClient(new TableClientConfiguration());

// Create a table client for interacting with the table service 
CloudTable table = tableClient.GetTableReference("MyTable");

//some code to populate an entity
var entity = new { PartitionKey = "Http", RowKey = Guid.NewGuid().ToString(), Text = input.Text };

// Create the InsertOrReplace table operation
TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity);

// Execute the operation.
TableResult result = await table.ExecuteAsync(insertOrMergeOperation);
您可以使用:

[FunctionName("TableOutput")]
[return: Table("MyTable")]
public static MyPoco TableOutput([HttpTrigger] dynamic input, ILogger log)
{
    log.LogInformation($"C# http trigger function processed: {input.Text}");
    return new MyPoco { PartitionKey = "Http", RowKey = Guid.NewGuid().ToString(), Text = input.Text };
}
PS:前面代码中的输入触发器是HTTP触发器,但只是解释如何使用输出绑定

您可以在此处找到更多信息:


你应该注意:

回答得很好。谢谢你的帮助,我会尝试一下…很好的答案。谢谢你的帮助,我会试试这个。。。