使用一个或多个标准FIFO队列实施延迟队列 [英] Implementing Delay Queue using one or more standard FIFO Queues

查看:97
本文介绍了使用一个或多个标准FIFO队列实施延迟队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

延迟队列是一个队列,其中每个消息都有一个与之关联的延迟时间,并且仅当其延迟到期时才可以获取消息.队列的开头是该消息,其延迟在过去最远的时候到期.如果没有延迟,则没有头,出队将返回null.

A delay queue is a queue in which each message has a delay time associated with it and a message can only be taken when its delay has expired. The head of the queue is that message whose delay expired furthest in the past. If no delay has expired there is no head and dequeue will return null.

实际上,我正在使用Azure编写云应用程序,并且在Azure中只有FIFO队列可用,而没有优先级/延迟队列.所以我来到这里是为了寻找是否有人可以给我一些指导,让我从正确的方向开始.我在Google上搜索了很多,但只发现了有关Java中延迟队列实现的信息,而没有标准的教程/研究论文讨论了一般的延迟队列.

Actually, I am writing a cloud application using Azure and in Azure only FIFO queues are available and not priority/delay queues. So I came here looking if someone can give me some pointers from where I can head start in the right direction. I googled a lot but only find out about the delay queues implementation in Java and no standard tutorial/research paper which talks about delay queues in general.

我有什么代码?
实际上,我必须首先设计这些东西并将其呈现给我的经理,一旦我们完成设计,那么只有我可以开始编码.

What I have code?
Actually, I have to first design this things and present it to my manager and once we finalize the design then only I can start coding.

有关该场景的更多详细信息
它是基于主/从模型的分布式应用程序.主节点产生消息并将其放入Azure Service Bus队列,并且有多个从节点(在多台计算机上运行)从节点读取消息并进行处理.如果主机发生故障,则其中一个从机将充当主机并开始生成消息.我不想在主服务器中存储任何状态信息,因为万一主服务器出现故障,所有这些状态信息也将随之存储.

More details about the scenario
Its a distributed application based on master/slave model. A master produce messages and put them into Azure Service Bus queues and there are multiple slaves (running on multiple machines) which read from queues and precess them. If in case a master goes down, then one of the slave acts as a master and starts producing messages. I don't want to store any state information in the master because in case master goes down all that state information will also goes with it.

推荐答案

Windows Azure队列消息具有将消息插入队列时指定的延迟(以秒为单位).直到达到超时延迟,消息才可见.请参阅此MSDN文章以查看API详细信息.

Windows Azure Queue messages have a delay, in seconds, that you specify when inserting a message onto the queue. A message won't be visible until that timeout delay is hit. See this MSDN article to see the API details.

隐形性超时也以各种语言SDK实现方式实现.由于您使用的是C#,因此这是 AddMessage()调用的样子.请注意, AddMessage()的第三个参数指定了隐藏超时:

The invisibility timeout is implemented in the various language SDK implementations as well. Since you're working with C#, here's what the AddMessage() call would look like. Note the 3rd parameter of AddMessage()specifies the invisibility timeout:

        var acct = CloudStorageAccount.DevelopmentStorageAccount;
        var queueClient = acct.CreateCloudQueueClient();
        var queue = queueClient.GetQueueReference("myqueue");
        queue.CreateIfNotExist();

        var msg = new CloudQueueMessage("test message");
        queue.AddMessage(msg, TimeSpan.FromHours(2), TimeSpan.FromMinutes(30));

这篇关于使用一个或多个标准FIFO队列实施延迟队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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