'Collect results from multiple Azure Function triggers

I have a setup where I use a queue system, an azure function storage trigger, an orchestrator and a durable function.

My flow is like this:

  1. An outside function place a json message in my storage queue.
  2. The Azure Function Trigger collects the message and sends the json message to the orchestration.
  3. My orchestrator then, based of the json message, starts a durable function.
  4. The durable function does its work, and ends with inserting some data into a database.

My problem is at step 1 I send "many" messages, sometimes 30, and it all runs smoothly. But I was thinking, if I at step 3, could collect the results of 30 durable function outputs, and then aggregate the results, so that I instead of inserting data 30 times into a sql server, only do it once.

The aggregation should then happen, if there is something like 10 seconds without a new message.

Is it even possible to achieve something like this with Azure Functions?



Solution 1:[1]

  • If you want to add messages a set number of messages to database at once instead of doing every time the blob storage trigger is triggered this can be possible by storing the data locally.

  • first of all, set a limit on number messages to be add to database as we cannot wait indefinitely. Then create local variable (which is equal to the limit set previously) and a local data structure (to store the messages) for example an array.

  • Now every time the trigger is triggered check whether the local variable is zero or not. If not zero, then store the message in the local data structure else if the value is zero add the entire data to the database and then set the local variable back the limit on number of messages to be add to the database so that we wait for the next chunk of messages.

Refer the following to create azure blob storage triggers and how to store data in database using azure function

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MohitGanorkar-MT