I am trying to receive the message from Azure Device Client as below
public async Task<List<string>> RecieveMessage(string correlationId)
{
var response = new List<string>();
InitializeDeviceClient("AMQP");
var flag = true;
while (flag)
{
Microsoft.Azure.Devices.Client.Message receivedMessage = await deviceClient.ReceiveAsync(TimeSpan.FromSeconds(120));
if (receivedMessage == null)
{
await Task.Delay(100).ConfigureAwait(false);
continue;
}
Trace.WriteLine(receivedMessage.CorrelationId.ToString());
await this.deviceClient.CompleteAsync(receivedMessage);
if (receivedMessage.CorrelationId != correlationId)
{
continue;
}
var content = Encoding.UTF8.GetString(receivedMessage.GetBytes());
response.Add(content);
flag = false;
}
return response;
}
When I filter the message based on particular 'CorrelationId' then I return the response.
Here at the step when I call 'CompleteAsync' exception is seen intermittently when running from VSTS.
Microsoft.Azure.Devices.Client.Exceptions.DeviceMessageLockLostException: Exception of type 'Microsoft.Azure.Devices.Client.Exceptions.DeviceMessageLockLostException' was thrown.
Stacktrace:
Microsoft.Azure.Devices.Client.Transport.AmqpIoT.AmqpIoTOutcome.ThrowIfError()
at Microsoft.Azure.Devices.Client.Transport.Amqp.AmqpTransportHandler.DisposeMessageAsync(String lockToken, AmqpIoTDisposeActions outcome)
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.<>c__DisplayClass23_0.<<ExecuteWithErrorHandlingAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation)
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass26_0.<<CompleteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.CompleteAsync(String lockToken, CancellationToken cancellationToken)
at Microsoft.Azure.Devices.Client.InternalClient.CompleteAsync(String lockToken)
question from:
https://stackoverflow.com/questions/65951483/devicemessagelocklostexception-is-thrown-from-azure-device-client-when-calling-c 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…