1

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.

gee kay
  • 11
  • 1
  • 2
  • `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 Apr 07 '17 at 09:42
  • 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 May 24 '17 at 07:18
  • 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 May 24 '17 at 07:27

1 Answers1

2

*

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://learn.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/

granadaCoder
  • 26,328
  • 10
  • 113
  • 146
  • thanks for you reply. Now am using a local string array and pushed all the received messages immediately and called BrokeredMessage.Complete(). then am using that local array for my process, So there is no possibility for lock expiration. But still messages are not removed from queue. – gee kay Apr 11 '17 at 05:21
  • Your approach is prone to possible lost messages. What happens when you pull 500 messages,... complete them all....then while processing, you get an unhandled exception or crash after 200 messages are processed? You could have to post a complete mini example (aka, the code)...when you call complete, the message should be removed from the queue. – granadaCoder Apr 12 '17 at 13:42