4

I receive queue message in worker role, but when I try to mark BrokeredMessage as complete. I get below error:

Client.OnMessage((receivedMessage) =>
    {
        try
        {
            FileContainer fileInfoObj = receivedMessage.GetBody<FileContainer>();               
            //Message processing code               

            receivedMessage.Complete();                           

        }
        catch
        {
            receivedMessage.DeadLetter();
        }
    });

The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue.

Am I missing something?

Abhijeet
  • 13,562
  • 26
  • 94
  • 175
  • 3
    How long is "Message processing code" taking? There is an expiration time for the lock. The default timeout is 1 minute. Use `QueueDescription.LockDuration` to change it. – Mike Zboray Aug 12 '14 at 16:23

1 Answers1

6

As per Mike Z's comment, set the LockDuration (default is 1, can be up to 5 mins) when you create the queue to prevent timeout.

QueueDescription qd = new QueueDescription("MyQueue");
qd.LockDuration = ...

if (!namespaceManager.QueueExists("MyQueue"))
{
    namespaceManager.CreateQueue(qd);
}

Also, use RenewLock to prevent it from timing out during a long process:

receivedMessage.RenewLock()

From here: https://stackoverflow.com/a/15305150/188926

Community
  • 1
  • 1
Dunc
  • 18,404
  • 6
  • 86
  • 103