0
votes

am using azure service bus messaging, in that i'm getting some strange issue.

i created a subscription client with "peeklock" mode. using SubscriptionClient.ReceiveBatch(500) method and received 'n' messages. then loop those messages and do my process, if my process is successfully completed then use BrokeredMessage.Complete() to remove that message from queue. if there is any issue in that process am using BrokeredMessage.Abandon() to renew the message. But the messages are not removed from queue.

after some analysis, i suspect my process taking more time and the message locks are getting expired before the the process complete.

Then i decided, after received the message from queue, i pushed those messages into local string array and then called BrokeredMessage.Complete(). So there is no possibility for lock expiration. But still messages are not removed from queue.

Kindly give some idea to fix this issue.

1
But still messages are not removed from queue. All of messages are not removed or part of messages are not removed? If it is possible, please share the reproduced demo code. - Tom Sun - MSFT
I was facing some old messages that would get in the way, Si I wrote a clearQueue function : var client = GetQueueClient(false, QueueName); do { messages = await client.PeekBatchAsync(10); messages.Select(async x => await x.CompleteAsync()); } while (messages.Any()); await client.CloseAsync();' When I debug this the Queue is empty, but when I write a Test that calls this code and checks if there are any messages they are all back again. - Null
All the time the client is in PeekLock mode await _esb.ClearQueue(); var msgs = await _esb.RecieveObjectsAsync(); Assert.IsTrue(!msgs.Any()); // this passes msgs = await _esb.PeekObjectsAsync(); Assert.IsTrue(!msgs.Any()); // boom they are back again... Does it have to do with the client beeing different? - Null

1 Answers

2
votes

*

BrokeredMessage.Abandon() to renew the message. But the messages are not removed from queue.

*

Abandon does not abandon the message. It Abandon's the LOCK.

https://docs.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.brokeredmessage.abandon?view=azureservicebus-4.0.0#Microsoft_ServiceBus_Messaging_BrokeredMessage_Abandon

Abandons the lock on a peek-locked message.

Abandon will definitely allow the message to become reavailable at a later time.

Call .Complete to get the message off the queue.

And you gotta be careful, as you suggest...about getting N (500 in your case) messages...and not being able to complete (all of) them before the lock mechanisms take effect.

Here are some ideas.

http://markheath.net/post/defer-processing-azure-service-bus-message

This is probably the best idea I've seen, however, it is by a single message.

http://dotnetartisan.in/2016/01/24/avoiding-messagelocklostexception-using-auto-renew-pattern-for-brokeredmessage-service-bus-queue/