Consume a few Azure Queue storages using the same consumer Azure Function App

Anonymous
2021-10-11T13:32:09.523+00:00

Hello all,

I am using an Azure Function App implemented in Java 8. The function uses Azure Queue as input binding.
Is it possible to set one function as a trigger for a few queues of Azure Queue storage?
If not, do you know a "clean" workaround to achieve it?

By default, the @QueueTrigger looks like:

   package com.function;  
   import com.microsoft.azure.functions.annotation.*;  
   import java.util.Queue;  
   import com.microsoft.azure.functions.*;  
     
   public class QueueTriggerDemo {  
       @FunctionName("QueueTriggerDemo")  
       public void run(  
           @QueueTrigger(name = "message", queueName = "messages", connection = "MyStorageConnectionAppSetting") String message,  
           final ExecutionContext context  
       ) {  
           context.getLogger().info("Queue message: " + message);  
       }  
   }  

The following code was copied from: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-trigger?tabs=java#attributes-and-annotations

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,118 questions
Azure Queue Storage
Azure Queue Storage
An Azure service that provides messaging queues in the cloud.
109 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Samara Soucy - MSFT 5,131 Reputation points
    2021-10-12T23:17:36.597+00:00

    Functions are only allowed one trigger each, but by organizing your logic into a separate method you could set up multiple functions that call that logic more easily. While not recommended generally, you can also define more than one function per class, and this might be somewhere you would want to bend that rule a bit.

    It would look something like this:

     public class QueueTrigger {
    
         DoStuff() {
             //stuff
         }
    
         @Function
         QueueTriggerOne() {
             DoStuff()
         }
    
         @Function
         QueueTriggerTwo() {
             DoStuff()
         }
    
         @Function
         QueueTriggerThree() {
             DoStuff()
         }
    
         //etc
    
     }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.