Whilst working with Azure functions you may come across a situation where you need
to return multiple items to a queue, it isn’t immediately obvious how to do that. Placing a message on the queue from within an
Azure Function typically involves placing the attribute
[return: Queue("function2Queue")]
on the main function body. But to add many messages
you must add a parameter decorated with
[Queue("function1Queue")] ICollector<__type__>
to the definition of the Run method.
The example below creates an HTTP Triggered function that places multiple messages on a queue to be processed by the second function:
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
[Queue("function1Queue")] ICollector<string> queueCollector)
{
queueCollector.Add("John Markson");
queueCollector.Add("Mark Johnson");
return new OkResult();
}
}
public static class Function2
{
[return: Queue("function2Queue")]
[FunctionName("Function2")]
public static async Task Run(
[QueueTrigger("function1Queue")] string message)
{
return $"C# Queue trigger function processed: {message}";
}
}