Two different Service Bus queue trigger function apps with same service bus name and queue

Azure-search 201 Reputation points
2023-05-21T14:00:06.99+00:00

Hi, I have two service bus queue triggers function apps with same service bus name and queue details, but pointing to different destinations. Is it possible for both service bus functions to get triggered for the same message and send the message twice?

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
620 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,950 questions
0 comments No comments
{count} votes

Accepted answer
  1. Konstantinos Passadis 19,076 Reputation points MVP
    2023-05-21T14:16:22.5333333+00:00

    Hello @Azure-search !

    Yes, it is indeed possible to have multiple Azure Functions triggered by the same message from an Azure Service Bus queue.

    However, the default behavior of Azure Service Bus is to use a "peek-lock" receive mode. This means when a function pulls a message from the queue, it is locked and made invisible to other receivers for a certain period of time. The function needs to complete (acknowledge) the message within this period, otherwise the message becomes visible again and can be processed by another function.

    In your case, if you have two different Function Apps listening to the same queue, the message will be processed by one of them first (due to the lock). Once that Function App completes processing and acknowledges the message, the message will be removed from the queue. Consequently, the other Function App won't see or process that message.

    If you want both Function Apps to process the same message, you would need to handle this differently. One way could be to use a Service Bus Topic instead of a Queue. Topics support publish/subscribe semantics, meaning a single message sent to the Topic can be received by multiple subscribers (each subscriber receives a copy of the message). This way, you can have multiple Function Apps each subscribing to the Topic and processing the messages independently.

    https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-queues-topics-subscriptions

    Image showing a Service Bus topic with three subscriptions.


     The answer or portions of it may have been assisted by AI Source: ChatGPT Subscription

    Kindly mark the answer as Accepted and Upvote in case it helped or post your feedback to help !

    Regards

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.