Using multiple Azure Functions QueueTriggers to listen on the same storage queue

懵懂的女人 提交于 2021-01-20 11:42:46

问题


I have an Azure Functions QueueTrigger that listens on a storage queue for messages like this:

Message text
--------------------------
{"ClientName": "client1"}
{"ClientName": "client2"}
{"ClientName": "client3"}

The QueueTrigger then has code like this:

if 'client1' == queue_msg['ClientName']:
    # do work required for client1
elif 'client2' == queue_msg['ClientName']:
    # do work required for client2
elif 'client3' == queue_msg['ClientName']:
    # do work required for client3

I'm using the Linux Consumption Plan with a batchSize of 1 because each invocation of the queue trigger can take about 5 minutes and I want to make sure I don't exceed memory limitations. This solution is working well for me now, but I'm concerned that when the amount of clients increases, messages will start to accumulate in the queue. Is it okay to just create a new Azure Function that also listens on the same storage queue? I think it would be okay because each message/client has work that is independent to them so it wouldn't matter if either of the Azure Function apps picked up a message first. This seems like the most cost effective solution for me, but I would like to know if there are better alternatives or any negative outcomes that I'm not thinking of.


回答1:


According to the description of your problem, you do not need to concern about the message accumulate. And you do not need to create another function to listen on the same storage queue. If you use consumption plan for your azure function, it will scale out more instances to deal with the messages. You can refer to this document.

===============================Update================================

According to your requirement of each instance running may use up to 1 GB memory, I suggest you to use "Premium plan" for your function.

When you create function app with premium plan, you can choose "EP1" as below screenshot. "EP1" plan has max 3.5GB memory, so it can scale out to 3 instances when the function running.

After the function app created, go to the function app and click "Scale out(App Service Plan)", then set "Maximum Burst" as 3. It means the plan will most scale out to 3 instances.

If you want more instances to run at same time, you can also choose "EP2" or "EP3" premium plan for your function app and change the value of "Maximum Burst".



来源:https://stackoverflow.com/questions/64708008/using-multiple-azure-functions-queuetriggers-to-listen-on-the-same-storage-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!