Azure队列存储触发的Webjob-一次使多条消息出队 [英] Azure Queue Storage Triggered-Webjob - Dequeue Multiple Messages at a time

查看:102
本文介绍了Azure队列存储触发的Webjob-一次使多条消息出队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure队列存储触发的Webjob.我的webjob执行的过程是将数据索引到Azure搜索中.Azure搜索的最佳实践是出于性能方面的考虑(将索引花费一些时间才能完成),而不是一次将多个项目一起建立索引.

由于这个原因,我希望我的Web作业将多条消息一起出队,以便我可以遍历,处理它们,然后将它们一起编入Azure搜索.

但是,我无法弄清楚如何使我的Web作业一次出库.如何做到这一点?

解决方案

由于这个原因,我希望我的Web作业将多条消息一起出队,以便我可以遍历,处理它们,然后将它们一起编入Azure搜索.

根据您的描述,建议您尝试使用Microsoft.Azure.WebJobs.Extensions.GroupQueueTrigger来满足您的要求.

此扩展程序将使您能够触发功能并接收消息组,而不是像[QueueTrigger]那样接收单个消息.

更多详细信息,您可以参考下面的代码示例和


如何将其更改为GroupQueueTrigger?这是一个容易的改变吗?

在我看来,这是一个容易的改变.

您可以按照以下步骤操作:

1.从Nuget软件包管理器安装软件包Microsoft.Azure.WebJobs.Extensions.GroupQueueTrigger.

2.更改program.cs文件,以启用UseGroupQueueTriggers.

3.根据旧的触发功能更改webjobs功能.

注意:组队列消息触发器必须使用列表.

如我的代码示例所示:

 公共静态无效值MyFunction([GroupQueueTrigger("queue3",10)]列表< string>消息) 

此函数将一次从"queue3"中获取10条消息,因此在此函数中,您可以更改函数循环消息列表并进行处理,然后将它们全部索引到Azure搜索中.

4.将您的网络作业发布到天蓝色的网络应用程序.

I have an Azure Queue Storage-Triggered Webjob. The process my webjob performs is to index the data into Azure Search. Best practice for Azure Search is to index multiple items together instead of one at a time, for performance reasons (indexing can take some time to complete).

For this reason, I would like for my webjob to dequeue multiple messages together so I can loop through, process them, and then index them all together into Azure Search.

However I can't figure out how to get my webjob to dequeue more than one at a time. How can this be accomplished?

解决方案

For this reason, I would like for my webjob to dequeue multiple messages together so I can loop through, process them, and then index them all together into Azure Search.

According to your description, I suggest you could try to use Microsoft.Azure.WebJobs.Extensions.GroupQueueTrigger to achieve your requirement.

This extension will enable you to trigger functions and receive the group of messages instead of a single message like with [QueueTrigger].

More details, you could refer to below code sample and article.

Install:

Install-Package Microsoft.Azure.WebJobs.Extensions.GroupQueueTrigger

Program.cs:

  static void Main()
        {
            var config = new JobHostConfiguration
            {
                StorageConnectionString = "...",
                DashboardConnectionString = "...."
            };
            config.UseGroupQueueTriggers();
            var host = new JobHost(config);
            host.RunAndBlock();
        }

Function.cs:

 //Receive 10 messages at one time
 public static void MyFunction([GroupQueueTrigger("queue3", 10)]List<string> messages)
        {
            foreach (var item in messages)
            {
                Console.WriteLine(item);
            } 
        }

Result:


How would I get that changed to a GroupQueueTrigger? Is it an easy change?

In my opinion, it is an easy change.

You could follow below steps:

1.Install the package Microsoft.Azure.WebJobs.Extensions.GroupQueueTrigger from Nuget Package manager.

2.Change the program.cs file enable UseGroupQueueTriggers.

3.Change the webjobs functions according to your old triggered function.

Note:The group queue message trigger must use list.

As my code sample shows:

 public static void MyFunction([GroupQueueTrigger("queue3", 10)]List<string> messages)

This function will get 10 messages from the "queue3" one time, so in this function you could change the function loop the list of the messages and process them, then index them all together into Azure Search.

4.Publish your webjobs to azure web apps.

这篇关于Azure队列存储触发的Webjob-一次使多条消息出队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆