Reputation: 13
I have an C# Azure Function that requests data from an API and writes it to Event hub. This is working. In the same function, I am then writing to a Azure Storage Account Table a watermarks value which is also working.
I want to query that watermark table first to get the watermark that has previously been written. I have tried aa few methods. However I can't get this working or know the best way to do this. Below is a summary of the Code that works with a line commented out that doesn't. I have tried a few ways of adding the query but can't find an example that works. I have tried multiple ways of doing this.
What is the best way for me to query the Cloud Table that I have written to using the watermarkTableCollector?
Appreciate your help.
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);
}
}
}
The above works but when I include the line (which uses the same connection and table I have written to)
//[Table("watermarks","WATERMARKS", Connection = "AzureWebJobsStorage")] CloudTable watermarksTable,
Error Message:
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'.
Upvotes: 0
Views: 164
Reputation: 13
Thanks all for feedback.
It seems that there have been a few ways to do this and there seem to be examples of doing it with deprecated packages. I opted for using the Azure Tables client library (Beta) which combines Cosmos and Storage Tables seamlessly so looks like a cleaner solution moving forward.
https://learn.microsoft.com/en-us/dotnet/api/overview/azure/data.tables-readme-pre
Upvotes: 1