Single Message Processing - Service Bus Triggered Azure Function

Prerna Bhand 20 Reputation points
2024-01-16T13:56:46.6766667+00:00

I have a Azure Function configured with a service bus trigger and a topic. The requirement is that only one message should be processed at a time by the function, and there should be absolutely no parallel processing. On top of it, FIFO message order should be followed. I do not have session enabled on the queue.

The Function is running on App Service Plan, EP1 with only one instance configured to run.

I could not achieve single message processing with the below host.json configuration . I assume here messageHandlerOptions will be honered since session is disabled.

However this along with the attribute [Microsoft.Azure.WebJobs.Singleton(Mode = SingletonMode.Function)] on the function worked. My understnading was that the below host.json without any attribute for Singleton should work, but it did not. Why is that so? Is this because the funciton is still managing concurrency in the configured instance, despite setting maxConcurrentCalls to 1? I am afraid if the Singleton attribute is the correct configuration. What should be the ideal setting here?

Also I have not enabled session here, assuming that since there is only one function process running at a time, FIFO should be automatically achieved. Is that correct assumption?

Thanks in advance

"functionTimeout": "00:10:00",
    "extensions": {
      "serviceBus": {
        "prefetchCount": 1,
        "messageHandlerOptions": {
          "autoComplete": true,
          "maxConcurrentCalls": 1,
          "maxAutoRenewDuration": "00:05:00"
        },
        "sessionHandlerOptions": {
          "autoComplete": true,
          "messageWaitTimeout": "00:05:00",
          "maxAutoRenewDuration": "00:55:00",
          "maxConcurrentSessions": 1
        },
        "queues": {
          "batchSize": 1,
          "newBatchThreshold": 1
        },
        "batchOptions": {
          "maxMessageCount": 1,
          "operationTimeout": "00:05:00",
          "autoComplete": true
        }
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
700 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ben Gimblett 4,560 Reputation points Microsoft Employee
    2024-01-16T17:27:07.98+00:00

    Hi Thanks for the question

    So the short answer; even though you only have one [Ep1] plan instance, which i presume you've set manually, you need to both control the in process trigger concurrency here (max concurrent calls) which you're doing .

    You dont need to batch in this scenario (so that config can be skipped) as it's an opt-in trigger functionality. (Opt in or out via the isBatched setting).

    You also need to control the function host. The singleton behaviour is the way to do that. Singleton is summed up in a line , in the following comment by Jeff Hollan https://github.com/Azure/azure-functions-host/issues/912#issuecomment-419608830

    As far as FIFO goes - service bus only makes the guarantee with sessions enabled - but yes with a singleton, single message processing sequentially it should work. However, assuming you're on a tier which supports it, and its a business critical requirement , I'd opt into using sessions even in this constrained scenario because then there's no ambiguity - the infrastructure will make the guarantee. REF https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-sessions#first-in-first-out-fifo-pattern for example there's no guarantee that without sessions a transient fault might not cause a change in order

    A similar Q&A here for ref https://learn.microsoft.com/en-us/answers/questions/494522/function-to-process-only-single-message-at-one-tim

    One other thing to mention here - doing what you're doing (single compute instance, singleton behaviour) does leave you vulnerable from a business continuity and SLA perspective - you dont have any resilience . if your function or the underlying host faults you will be at risk of downtime. Using session mitigates this as it allows co-ordinated locking and session management between receivers (as explained in that last link)

    1 person found this answer helpful.
    0 comments No comments

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.