Problem: I need to reschedule/defer a message to be processed after a user defined elapsed time as the receiver.
Goal: After a HttpReponseException of ServerUnavailable, I would like to retry processing of the message after 30 minutes. It must also follow the rule set being after 10 delivery attempts the message is sent to the dead letter queue (Happens automatically based on the topic rules).
So I have a function app to process a Azure Service Bus Topic. This means that thread sleeping is not an option.
What I have tried:
- I understand
messageSender.ScheduleMessageAsync(message, dateTime)
is used on the senders side to schedule the message for later processing which works when sending a new message, however, I as the receiver would like to do this on my side after getting an exception. - I tried using
messageReceiver.DeferAsync(message.SystemProperties.LockToken, properties)
, properties containing the new "ScheduledEnqueueTimeUtc" and this does defer the message but the Sequence ID's seem to go out of sync making it impossible to receive my deferred message. - If I clone the message I cannot set the
SystemProperty.DeliveryCount
as it is readonly hence the Dead Letter Queue Rule will not function as intended. I can createUserProperty's
and manually count message reties and a scheduled date in my function app but I am wondering if there is a better way to do this?
Any suggestions will be appriciated.