TheBlueSky
TheBlueSky

Reputation: 5948

Can I queue multiple items from a single run of an Azure Function?

I have a Node.js timerTrigger Azure function that processes a collection and queues the processing results for further processing (by a Node.js queueTrigger function).

The code is something like the following:

module.exports = function (context, myTimer) {
    collection.forEach(function (item) {
        var items = [];

        // do some work and fill 'items'

        var toBeQueued = { items: items };

        context.bindings.myQueue = toBeQueued;
    });

    context.done();
};

This code will only queue the last toBeQueued and not each one I'm trying to queue.

Is there any way to queue more than one item?

Update

To be clear, I'm talking about queueing a toBeQueued in each iteration of forEach, not just queueing an array. Yes, there is an issue with Azure Functions because of which I cannot queue an array, but I have a workaround for it; i.e., { items: items }.

Upvotes: 2

Views: 2651

Answers (2)

Chris Anderson
Chris Anderson

Reputation: 8515

Mathewc's answer is the correct one wrt Node.

For C# you can today by specifying ICollector<T> as the type of your output queue parameter.

Below is an example I have of two output queues, one of which I add via a for loop.

public static void Run(Item inbound, DateTimeOffset InsertionTime, ICollector<Item> outbound, ICollector<LogItem> telemetry, TraceWriter log)
{
    log.Verbose($"C# Queue trigger function processed: {inbound}");

    telemetry.Add(new LogItem(inbound, InsertionTime));

    if(inbound.current_generation < inbound.max_generation)
    {
        for(int i = 0; i < inbound.multiplier; i++) {
            outbound.Add(Item.nextGen(inbound));
        }
    }
}

Upvotes: 4

mathewc
mathewc

Reputation: 13558

Not yet, but we'll address that within the week, stay tuned :) You'll be able to pass an array to the binding as you're trying to do above.

We have an issue tracking this in our public repo here. Thanks for reporting.

Upvotes: 5

Related Questions