I have a function, triggered off a service bus. The bus contains data from several sources, which I want to process and write to a storage table. I can’t guarantee there won’t be duplicate entries in the bus, but require unique entries in the table. I’ve figured out I can access an IAsyncCollector
of my object type, but this doesn’t have a way to search for objects that already exist, or to update them. Here’s my current function code:
[FunctionName(nameof(Run))]
public async Task Run([Microsoft.Azure.WebJobs.ServiceBusTrigger("myBus", Connection = "myCon")] ServiceBusReceivedMessage message,
[Table("Widgets", Connection = "AzureWebJobsStorage")] IAsyncCollector<Widgets> widgetsTable,
ILogger log)
{
log.LogInformation($"queue trigger function processed message");
}
How do I access the table in a way that allows me to find/update objects?
2
Answers
You cannot use the output binding for that:
(source)
So you need to remove the output binding and leverage the table SDK directly.
I do this using a TableClient and let it deal with duplicates. It will either insert or update a row in a table depending on whether it exists or not.
If you need to know whether what you are updating in the table is the one you want, i.e. perhaps has the latest data for the object, you can use the TableClient directly to query the table to see if what’s already in there is "out of date" etc.