简体   繁体   中英

azure service bus message reappear timeout

If I have a service bus brokered message receiver configured. and it fails for any reason. I call on it

 message.abandon();

however this means the message will be back again in the queue/subscription.

can i configure a timeout after which the same message is available in the queue for processing.

For example: if there is only one message in the queue. and it's failing, then it is not good to keep processing it every second or every minute. if i configure something, that can make sure, the failed/abandoned message only reappears after 30 mins . then it is useful.

Any suggestions?

When you abandon a message, you cannot supply a "cool off" time. The message will be available right away. It won't be dead-lettered until MaxDeliveryCount attempts have been exhausted. Once all those processing attempts have been used up, the message will go to the dead-letter queue.

If you need to postpone message processing, there are several options.

Deferring a message

You could defer a message using BrokeredMessage.DeferAsync() . The message will go back to the queue for future processing and a SequenceNumber of the message will be returned. The caveat with this approach is the need to hold on to the SequenceNumber in order to retrieve the message later. If you happened to lose SequenceNumber , it is still possible to browse for deferred messages and retrieve those. More information here .

Scheduling a new future message

Another option would be to clone an incoming failing message, schedule it for some time in future using BrokeredMessage.ScheduledEnqueueTimeUTC and completing the original message. With this option, I'd recommend to send the new message scheduled in future to be dispatch using send-via feature , also known as Transaction Processing , to leverage atomic operation of completing the incoming message and sending the outgoing one. This way the code will not produce "ghost" message if completion fails. More information here .

Scheduling using client, not message

Another option is to schedule using a client and not BrokeredMessage using client.ScheduleMessageAsync(). It will return a client.ScheduleMessageAsync(). It will return a SequenceNumber` you need to hold on to, but using this API a message can be cancelled at any point in time w/o waiting for the schedule time to arrive or receiving the message. More information here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM