0
votes

Is it possible for an Azure Function to read messages from an Azure Event Hub by a single thread?

I'm trying to perform in-order processing as the article below shows but I think a second Azure Function thread is picking up event hub message data causing data issues.

https://medium.com/@jeffhollan/in-order-event-processing-with-azure-functions-bb661eb55428

1
As explained in the article, Azure Function has no notion of order, the order comes from your Hub partitions.James
Thanks for the reply. I've only got 1 Event Hub partition set up so I'm not sure how there can be multiple threads running but that appears to be the behavior.Richard Butterwood
@RichardButterwood Have you tried the method in last paragraph Triggering in ordered batches? The article talks about setting maxBatchSize to 1 to avoid concurrent behavior but recommends the ordered batches for performance consideration.Jerry Liu
I do use the MaxBatchSize option. I think when the Azure Function determines it is getting overloaded it creates another thread which is normal behavior for Azure Functions that are on the consumption plan.Richard Butterwood

1 Answers

0
votes

when the Azure Function determines it is getting overloaded it creates another thread which is normal behavior for Azure Functions that are on the consumption plan.

Your assumption is basically right, as the doc says,

scale controller automatically scales CPU and memory resources by adding additional instances of the Functions host, based on the number of events that its functions are triggered on

But I also see the tutorial along with the doc mentions

a single partition will only have a lease on one processor host at a time. That means multiple function instances can’t pull messages from the same partition.

Hence setting maxBatchSize to 1 is supposed to avoid concurrent in single partition reading.

If this doesn't guarantee the singleton, I suggest you add WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT with value 1 in Application settings to ensure no more host instances will be created.