gpt4 book ai didi

c# - Azure Function - 问题查询存储帐户云表

转载 作者:行者123 更新时间:2023-12-03 06:53:58 26 4
gpt4 key购买 nike

我有一个 C# Azure 函数,它从 API 请求数据并将其写入事件中心。这是有效的。在同一函数中,我向 Azure 存储帐户表写入一个水印值,该值也有效。

我想先查询水印表以获取之前写入的水印。我尝试了一些方法。但是我无法让它工作或知道最好的方法来做到这一点。下面是代码的摘要,其中注释掉了不适用的行。我尝试了几种添加查询的方法,但找不到有效的示例。我尝试了多种方法来做到这一点。

使用 watermarkTableCollector 查询已写入的云表的最佳方式是什么?

感谢您的帮助。

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Azure.WebJobs.Extensions.Tables;
using Microsoft.Azure.WebJobs.Extensions.Storage;
//using Microsoft.Azure.Cosmos;
using Newtonsoft.Json;
using System.Collections.Generic;

namespace fa_watermark_poc
{
public class DataTransfer
{

[FunctionName("ToEventHub")]
public static async Task Run([TimerTrigger("0 */1 * * * *", RunOnStartup = true)] TimerInfo myTimer,
[EventHub("EventsFromAPI", Connection = "EventHubConnectionAppSetting")] IAsyncCollector<string> outputEvents,
[Table("watermarks", Connection = "AzureWebJobsStorage")] IAsyncCollector<WatermarkTable> watermarkTableCollector,
//[Table("watermarks","WATERMARKS", Connection = "AzureWebJobsStorage")] CloudTable watermarksTable,
ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

TestInterface ti = new TestInterface(@https://test, "password");
var courses = ti.GetCourses();
string json = JsonConvert.SerializeObject(courses);

var watermark = new Watermark
{
WatermarkName = "TestSystemName"
};
await watermarkTableCollector.AddAsync(watermark.ToTable());
await outputEvents.AddAsync(json);
}
}
}
<小时/>

上面的方法有效,但是当我包含该行时(使用与我写入的相同的连接和表)//[Table("watermarks","WATERMARKS", Connection = "AzureWebJobsStorage")] CloudTable watermarksTable,

我收到以下错误

错误消息:

Azure Functions Core Tools
Core Tools Version: 4.0.4653 Commit hash: N/A (64-bit)
Function Runtime Version: 4.6.1.18388

[2022-08-09T21:51:08.192Z] Found ...\source\repos\fa_watermark_poc\fa_watermark_poc\fa_watermark_poc.csproj. Using for user secrets file configuration.
[2022-08-09T21:51:13.689Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'ToEventHub'. Microsoft.Azure.WebJobs.Extensions.Tables: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.
[2022-08-09T21:51:13.715Z] Error indexing method 'ToEventHub'
[2022-08-09T21:51:13.715Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'ToEventHub'. Microsoft.Azure.WebJobs.Extensions.Tables: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.
[2022-08-09T21:51:13.716Z] Function 'ToEventHub' failed indexing and will be disabled.
[2022-08-09T21:51:13.718Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
[2022-08-09T21:51:13.744Z] The 'ToEventHub' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'ToEventHub'. Microsoft.Azure.WebJobs.Extensions.Tables: Can't bind Table to type 'Microsoft.WindowsAzure.Storage.Table.CloudTable'.
<小时/>

最佳答案

感谢大家的反馈。

似乎有几种方法可以做到这一点,并且似乎有使用已弃用的软件包进行此操作的示例。我选择使用 Azure Tables 客户端库(测试版),它将 Cosmos 和存储表无缝结合在一起,因此看起来是一个更干净的解决方案。

https://learn.microsoft.com/en-us/dotnet/api/overview/azure/data.tables-readme-pre

关于c# - Azure Function - 问题查询存储帐户云表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73299072/

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