将Azure Azure Queue BrokeredMessage标记为已成功处理?

Abh*_*eet 4 c# azure

我以worker角色接收队列消息,但是当我尝试标记BrokeredMessage为完成时.我得到以下错误:

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

            receivedMessage.Complete();                           

        }
        catch
        {
            receivedMessage.DeadLetter();
        }
    });
Run Code Online (Sandbox Code Playgroud)

提供的锁无效.锁已过期,或者消息已从队列中删除.

我错过了什么吗?

Dun*_*unc 6

根据Mike Z的评论,在创建队列以防止超时时设置LockDuration(默认值为1,最长可达5分钟).

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

if (!namespaceManager.QueueExists("MyQueue"))
{
    namespaceManager.CreateQueue(qd);
}
Run Code Online (Sandbox Code Playgroud)

此外,使用RenewLock防止它在漫长的过程中超时:

receivedMessage.RenewLock()
Run Code Online (Sandbox Code Playgroud)

从这里:https: //stackoverflow.com/a/15305150/188926