如何保证azure队列的先进先出

发布于 2024-12-05 06:22:53 字数 298 浏览 1 评论 0原文

我了解 MS Azure 队列服务文档 http://msdn.microsoft.com /en-us/library/windowsazure/dd179363.aspx 表示不保证先出 (FIFO) 行为。

然而,我们的应用程序必须按 FIFO 顺序读取和处理所有消息。有人可以建议如何使用 Azure 队列服务实现有保证的 FIFO 吗?

谢谢。

I understand that MS Azure Queue service document http://msdn.microsoft.com/en-us/library/windowsazure/dd179363.aspx says first out (FIFO) behavior is not guaranteed.

However, our application is such that ALL the messages have to be read and processed in FIFO order. Could anyone please suggest how to achieve a guaranteed FIFO using Azure Queue Service?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

南街九尾狐 2024-12-12 06:22:53

docs 表示:

存储队列中的消息通常是先进先出的,但有时它们可​​能是无序的;例如,当一条消息
可见性超时持续时间到期(例如,由于
客户端应用程序在处理过程中崩溃)。当能见度
超时到期,消息在队列中再次可见
另一个工人将其出队。此时,新可见的消息
可能会在一条消息之后被放入队列中(再次出队)
最初是在它之后排队的。

也许这对你来说已经足够了?否则使用服务总线。

The docs say for Azure Storage queues that:

Messages in Storage queues are typically first-in-first-out, but sometimes they can be out of order; for example, when a message's
visibility timeout duration expires (for example, as a result of a
client application crashing during processing). When the visibility
timeout expires, the message becomes visible again on the queue for
another worker to dequeue it. At that point, the newly visible message
might be placed in the queue (to be dequeued again) after a message
that was originally enqueued after it.

Maybe that is good enough for you? Else use Service bus.

属性 2024-12-12 06:22:53

最新的服务总线版本提供可靠的消息队列:队列、主题和订阅

The latest Service Bus release offers reliable messaging queuing: Queues, topics and subscriptions

欢你一世 2024-12-12 06:22:53

不幸的是,许多答案误导了服务总线队列,但我认为问题是关于提到的标签中的存储队列。在 Azure 存储队列 中,不保证 FIFO,而在 Service Bus 中,保证 FIFO 消息排序,而且也只能使用一个称为会话的概念。

一个简单的场景可能是,如果任何消费者从队列中接收到一条消息,当您作为第二个接收者时,它对您来说是不可见的。因此,您假设收到的第二条消息实际上是第一条消息(其中 FIFO 失败:P)

如果这不是您的要求,请考虑使用服务总线。

Unfortunately, many answers misleads to Service Bus Queues but I assume the question is about Storage Queues from the tags mentioned. In Azure Storage Queues, FIFO is not guranteed, whereas in Service Bus, FIFO message ordering is guaranteed and that too, only with the use of a concept called Sessions.

A simple scenario could be, if any consumer receives a message from the queue, it is not visible to you when you are the second receiver. So you assume the second message you received is actually the first message (Where FIFO failed :P)

Consider using Service Bus if this is not your requirement.

挽你眉间 2024-12-12 06:22:53

添加到 @RichBower 答案...查看此...Azure 存储队列与 Azure 服务总线队列

MSDN(链接已停用)
http://msdn.microsoft.com/en-us/library/ windowsazure/hh767287.aspx

learn.microsoft.com
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-azure-and-service-bus-queues-compared-contrasted

Adding to @RichBower answer... check out this... Azure Storage Queues vs. Azure Service Bus Queues

MSDN (link retired)
http://msdn.microsoft.com/en-us/library/windowsazure/hh767287.aspx

learn.microsoft.com
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-azure-and-service-bus-queues-compared-contrasted

一张白纸 2024-12-12 06:22:53

我不知道您希望处理消息的速度有多快,但是如果您需要有一个真正的 FIFO,请不要允许 Azure 的队列一次获取多于一条消息。

在函数顶部的“program.cs”中使用它。

    static void Main()
            {
                var config = new JobHostConfiguration();

                if (config.IsDevelopment)
                {
                    config.UseDevelopmentSettings();
                }
                config.Queues.BatchSize = 1; //Number of messages to dequeue at the same time.
                config.Queues.MaxPollingInterval = TimeSpan.FromMilliseconds(100); //Pooling request to the queue.


                JobHost host = new JobHost(config);

....your initial information...

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();

这将一次收到一条消息,等待时间为 100 毫秒。

这与记录器网络作业完美配合,将 traze 信息写入文件。

I don't know how fast do you want to process the messages, but if you need to have a real FIFO, don't allow Azure's queue to get more than one message at a time.

Use this at your "program.cs" at the top of the function.

    static void Main()
            {
                var config = new JobHostConfiguration();

                if (config.IsDevelopment)
                {
                    config.UseDevelopmentSettings();
                }
                config.Queues.BatchSize = 1; //Number of messages to dequeue at the same time.
                config.Queues.MaxPollingInterval = TimeSpan.FromMilliseconds(100); //Pooling request to the queue.


                JobHost host = new JobHost(config);

....your initial information...

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();

This will get one message at a time with a wait period of 100 miliseconds.

This is working perfectly with a logger webjob to write to files the traze information.

猫性小仙女 2024-12-12 06:22:53

正如这里提到的 https:/ /www.jayway.com/2013/12/20/message-ordering-on-windows-azure-service-bus-queues/ 服务中也不保证排序总线,除了使用有风险的接收和删除模式

As mentioned here https://www.jayway.com/2013/12/20/message-ordering-on-windows-azure-service-bus-queues/ ordering is not guaranteed also in service bus, except of using recieve and delete mode which is risky

苦妄 2024-12-12 06:22:53

您只需要按照以下步骤来确保消息排序:

1) 创建一个会话启用= false 的队列。
2) 在队列中保存消息时,提供会话 ID,如下所示:-

var message = new BrokeredMessage(item);
message.SessionId = "LB";
Console.WriteLine("Response from Central Scoring System : " + item);
client.Send(message);

3) 创建接收者以恢复消息时:-

queueClient.OnMessage(s =>
{
    var body = s.GetBody<string>();
    var messageId = s.MessageId;
    Console.WriteLine("Message Body:" + body);
    Console.WriteLine("Message Id:" + messageId);
});

4) 当具有相同的会话 ID 时,它会自动确保顺序并给出有序消息。

谢谢!!

You just need to follow below steps to ensure Message ordering.:

1) Create a Queue with session enabled=false.
2) While saving message in the queue, provide the session id like below:-

var message = new BrokeredMessage(item);
message.SessionId = "LB";
Console.WriteLine("Response from Central Scoring System : " + item);
client.Send(message);

3) While creating receiver for reviving message:-

queueClient.OnMessage(s =>
{
    var body = s.GetBody<string>();
    var messageId = s.MessageId;
    Console.WriteLine("Message Body:" + body);
    Console.WriteLine("Message Id:" + messageId);
});

4) While having the same session id, it would automatically ensure order and give the ordered message.

Thanks!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文