3

I have a process written in a console application right now that fires on a scheduled task to read data from Azure table storage and based on that data, make API calls to a third party vendor we use, deserialize the response data, loop over an array in the results, save the individual iterations of the loop into a different table in Azure table storage, and then publish messages for each iteration of the loop to Azure service bus where those messages are consumed by another client.

In an effort to get more of our tasks into the cloud, I've done some research and it seems that an Azure function would be a good candidate to replace my console application. I spun up a new Azure function project in Visual Studio 2019 as a "timer" function and then dove into some reading where I got lost really fast.

The reading I've done talks about using "bindings" in my Run() method arguments decorated with attributes for connection strings etc but I'm not sure that is the direction I should be heading. It sounds like that would make it easier for authentication to my table storage, but I can't figure out how to use those "hooks" to query my table and then perform inserts. I haven't even gotten to the service bus stuff yet nor looked into making HTTP calls to our third party vendor's api.

I know this is a very broad question and I don't have any code to post because I'm having a tough time even getting out of the starting blocks with this. The MS documentation is all over the map and I can't find anything specific to my needs and I promise I've spent a fair bit of time trying.

Are Azure functions even the right path I should be travelling? If not, what other options are out there?

TIA

Blair Holmes
  • 1,521
  • 2
  • 22
  • 35

1 Answers1

4

You should keep with Azure Functions with the Time Trigger to replace your console app.

The bindings (which can be used for input /output) are helpers to save you some lines of code, for example:

Rather than using the following code to insert data into azure table:

// 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);

you would use:

[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: the input trigger in the previous code is a HTTP Trigger, but was only to explain how to use output binding.

you can find more information in here:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-table

and you should watch: https://learn.microsoft.com/en-us/learn/modules/chain-azure-functions-data-using-bindings/

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90