天蓝色队列存储-将消息放回队列 [英] azure queue storage - putting a message back in the queue

查看:92
本文介绍了天蓝色队列存储-将消息放回队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个处理Web作业的队列,以从队列中读取消息,并使用该数据从Blob存储中检索报告uri,然后将其作为电子邮件中的链接发送。我的程序运行良好,但是我需要在特定的时间范围内发送电子邮件。

Im building a queue processing webjob to read messages from a queue and use the data to retrieve a report uri from blob storage then send this as a link in an email. I have the process working perfectly well, but I need to send the email within a specific time window.

我有另一个进程(webjob),它从sql后端检索此数据并将其放置在电子邮件队列中。

I have another process (webjob) that retrieves this data from a sql backend and places it in the email queue.

此网络作业每30分钟运行一次,仅获取当日和当前时间2小时内的数据。因此,我知道队列中的所有内容都是今天和现在两个小时之内。我如何进一步缩小此范围以从队列中读取数据,并且如果 email out时间设置为19:00,而当前时间是18:00,则可以将此消息放回队列中以进行读取再过一遍,下一次应该在19:00左右,然后我可以对其进行处理并通过电子邮件发送出去。

时间不必一定要紧,所以即使在该时间之内,例如19:00的30分钟(或发送设置的任何时间)都可以进行处理。因此,Im有效地从队列中取出了一个对象,检查了它的时间,如果不在分配的 email out时间之内说了30分钟之内,我将其放回队列中,并再次对其进行处理

This webjob runs every 30 mins and only gets data for the current day and within a 2 hour window of the current time. So I know that anything in the queue is for today and within 2 hours of 'now'. How would i narrow this down further to read data from the queue, and if the 'email out' time is set to say 19:00 and the current time is 18:00, I can put this message back in the queue to read it again later, next time it should be closer to 19:00 then I can process it and send it out in an email.
The time doesn't have to be spot on, so even if its within, say 30 mins of 19:00 (or whatever time its set to be sent) It can be processed. So Im effectively taking an object from the queue, checking its time and if its not within say 30 mins of its allotted 'email out' time, I place it back in the queue and its processed again

**在我的Web作业中,我有一个函数类,其中包含方法 ProcessQueueMessage,该方法在消息放入队列时都会触发。

** in my webjob, I have a 'Functions' class that contains a method 'ProcessQueueMessage' which is triggered whenever a message is placed in the queue.

// This function will get triggered/executed when a new message is written 
    // on an Azure Queue called queue.
    public async Task ProcessQueueMessage([QueueTrigger("%reportgenerator%")] Data.Dto.Schedule.ScheduleDto schedule)
    {
        var reports = await this._scheduledReportGenerationService.GenerateScheduledEmails(schedule.ID);
    }

ScheduleDto类将具有生成时间属性,我可以阅读并进行比较将其设置为当前时间并仅在其指定的时间窗口内对其进行处理。我如何停止在此处删除队列消息以便重新处理它?<​​/ p>

The ScheduleDto class will have a generation time property, I can read this and compare it to the current time and process it only if its within my specified 'time window'. How would i stop the queue message from being deleted here so that I can re-process it ?

推荐答案

添加消息时只需将initialVisibilityDelay设置到队列中,就可以在最短处理时间之前看不到该消息。

When you add the message to the queue just set the initialVisibilityDelay so that the message isn't seen until the minimum process time.

CloudQueue queue = queueClient.GetQueueReference(queueName);
var msg = new CloudQueueMessage("Hello World!");
TimeSpan timeSpanDelay = GetEarliestProcessTime();
await queue.AddMessageAsync(msg, null, timeSpanDelay, null, null);

CloudQueue.AddMessage

这篇关于天蓝色队列存储-将消息放回队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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