我以worker角色接收队列消息,但是当我尝试将brokeredMessage标记为完成时.我得到以下错误:
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.
我错过了什么吗?
解决方法:
根据Mike Z的评论,在创建队列以防止超时时设置LockDuration(默认值为1,最长可达5分钟).
QueueDescription qd = new QueueDescription("MyQueue");
qd.LockDuration = ...
if (!namespaceManager.QueueExists("MyQueue"))
{
namespaceManager.CreateQueue(qd);
}
另外,使用RenewLock防止它在长时间过程中超时:
receivedMessage.RenewLock()