ServiceBus: Message lock auto-renew
See original GitHub issueWorking with the c# ServiceBus SDK it would seem that there is an auto-renew of the locks that happens behind the scenes for long running message related workflows. However, in the Java world this functionality doesn’t exist. This means when I am working with messages I have to always write boilerplate code that will execute a scheduled thread pool to renew the locks, or my messages get abandoned etc.
Describe the solution you’d like
Having looked at the SDK it would seem that the MessageReceiver
could have an additional property added to set auto-renew on or possibly take a configuration object to its constructor. If this is set to true then we could have a new object of type AutoRenewMessage
that implements IMessage
or even could inherit Message
and extend it.
MessageReciever
can be extended to have a ScheduledThreadPool
that will keep track of these AutoRenewMessage
using a new Runnable
for example:
public class MessageLockAutoRenewTask implements Runnable {
private final IMessageReceiver receiver;
private final IMessage message;
public MessageLockAutoRenewTask(IMessageReceiver receiver, IMessage message) {
this.receiver = receiver;
this.message = message;
}
@Override
public void run() {
try {
this.receiver.renewMessageLock(message.getLockToken());
} catch (InterruptedException ex) {
// do something else here
} catch (ServiceBusException ex) {
// do something here
}
}
}
If the MessageReceiver
was to be closed/disposed then the ScheduledThreadPool
can be abandoned and all executing tasks will naturally close down.
When a message is abandoned, DLQ’d or completed it would just be a matter of checking if the IMessage
is of type Message
or AutoRenewMessage
and then making sure the object stopped its scheduled task.
Describe alternatives you’ve considered
- Extend the existing MessageReciever to have a new AutoRenewMessageReciever and then maintain message states on a concurrent collection.
- Implement a new intermediary class similar to the c# library whereby all calls to the
CoreMessageReciever
go through this intermediary object and it tracks the state of messages in flight and renews the locks etc.
Additional context
- I am currently working on a POC of this new code and was just wanting to raise this Issue as a proposal before I get round to raising a PR to get feedback regarding the approach and if the PR would be accepted?
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Description Added
- Expected solution specified
Issue Analytics
- State:
- Created 4 years ago
- Comments:14 (4 by maintainers)
@storey247
The auto renewal is only supported through Message (or Session) Handlers. Even in C#, if you utilize the MessageReceiver, then you have to explicitly renew the lock using RenewLockAsync(). see this comment
Why not leverage MessageHandler In Java and set MaxAutoRenewDuration in MessageHandlerOptions to manage the lock renewal?
Let us know if you have any further questions.
Closing this issue as there are no plans to add this feature to the older
com.azure:azure-messaging-servicebus
. Please do try the newercom.microsoft.azure:azure-servicebus
package as mentioned in the previous comment and share any feedback you have.