Question

The run method of my worker role is:

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);                 
        }
    }
}

For performance tests I would that a message could be analysed only by a worker (I don't consider failure problems on workers).

But seems by my tests, that two workers can pick up the same message and read DequeueCount equals to 1 (both workers). Is it possible?

Does exist a way that allow just a worker to read a message in a "mutex" way?

Was it helpful?

Solution

How is your "getAMessage(queue)" method defined? If you do PeekMessage(), a message will be visible by all workers. If you do GetMessage(), the message will be got only by the worker which firsts get it. But for the invisibility timeout either specified or the default (30 sec.). You have to delete the message before the invisibility timeout comes.

Check out the Queue Service API for more information. I am sure that there is something wrong in your code. I use queues and they behave as by documentation in dev storage and in production storage. You may want to explicitly put higher value of the Visibility Timeout when you do GetMessage. And make sure you do not sleep longer than the visibility timeout.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top