侦听同一存储队列

侦听同一存储队列

本文介绍了使用多个Azure Functions QueueTriggers侦听同一存储队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure Functions QueueTrigger,它在存储队列上侦听以下消息:

 消息文本--------------------------{"ClientName":"client1"}{"ClientName":"client2"}{"ClientName":"client3"} 

然后QueueTrigger具有如下代码:

 如果'client1'== queue_msg ['ClientName']:#做client1所需的工作elif'client2'== queue_msg ['ClientName']:#做client2所需的工作elif'client3'== queue_msg ['ClientName']:#做client3所需的工作 

我使用的Linux消费计划的 batchSize 1 ,因为队列触发器的每次调用可能需要5分钟左右,因此我想确保不会超出内存限制.现在,该解决方案对我来说效果很好,但是我担心,随着客户端数量的增加,消息将开始在队列中累积.可以创建一个新的同时在同一存储队列上侦听的Azure函数吗?我认为这是可以的,因为每个消息/客户端的工作都独立于它们,因此,如果两个Azure Function应用程序中的任何一个都首先接收到消息都没有关系.对于我来说,这似乎是最具成本效益的解决方案,但我想知道是否有更好的选择或我没有想到的负面结果.

解决方案

根据对问题的描述,您无需担心消息的累积.而且,您无需创建另一个函数即可侦听同一存储队列.如果您将

================================ 更新 ===============================

根据您的要求,每个实例运行可能最多使用1 GB内存,因此建议您使用"

创建功能应用程序后,转到功能应用程序并单击"横向扩展(应用程序服务计划)",然后设置"最大突发次数".作为 3 .这意味着该计划最多可扩展到3个实例.

如果您希望同时运行更多实例,则还可以选择" EP2 "或" EP3 "您的功能应用的高级计划,并更改"最大爆发次数"的值.

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.

解决方案

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".

这篇关于使用多个Azure Functions QueueTriggers侦听同一存储队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 20:39