【问题标题】:Azure Worker: Read a message from the Azure queue in a mutex wayAzure Worker:以互斥方式从 Azure 队列中读取消息
【发布时间】:2012-02-03 10:32:25
【问题描述】:

我的worker角色的run方法是:

public override void Run()
{
    Message msg=null;
    while (true)
    {

        msg = queue.GetMessage();
        if(msg!=null && msg.DequeueCount==1){
             //delete message
             ...
             //execute operations
             ...
        }
        else if(msg!=null && msg.DequeueCount>1){
             //delete message
             ...
        }
        else{
             int randomTime = ...
             Thread.Sleep(randomTime);                 
        }
    }
}

对于性能测试,我希望只能由工作人员分析消息(我不考虑工作人员的故障问题)。

但根据我的测试,似乎两个工人可以接收相同的消息并读取 DequeueCount 等于 1(两个工人)。是否可以?

是否存在仅允许工作人员以“互斥”方式读取消息的方式?

【问题讨论】:

    标签: performance design-patterns azure azure-worker-roles azure-storage-queues


    【解决方案1】:

    您的“getAMessage(queue)”方法是如何定义的?如果您执行PeekMessage(),则所有工作人员都可以看到一条消息。如果您执行GetMessage(),则该消息将仅由首先获得它的工人获得。但是对于指定或默认(30 秒)的隐形超时。您必须在隐身超时到来之前删除该消息。

    查看Queue Service API 了解更多信息。我确信你的代码有问题。我使用队列,它们的行为与开发存储和生产存储中的文档一样。当您执行GetMessage 时,您可能希望显式设置更高的Visibility Timeout 值。并确保您的睡眠时间不超过能见度超时时间。

    【讨论】:

    • 我使用queue.GetMessage()
    猜你喜欢
    • 1970-01-01
    • 2021-06-21
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 2021-10-18
    相关资源
    最近更新 更多