question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ServiceBus: Message lock auto-renew

See original GitHub issue

Working 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:closed
  • Created 4 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
axisccommented, Sep 27, 2019

@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.

0reactions
ramya-rao-acommented, Sep 20, 2021

Closing this issue as there are no plans to add this feature to the older com.azure:azure-messaging-servicebus. Please do try the newer com.microsoft.azure:azure-servicebus package as mentioned in the previous comment and share any feedback you have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Service Bus message transfers, locks, and settlement
The client owning the lock can renew the message lock by using methods on the receiver object. Instead, you can use the automatic...
Read more >
Autotmatically renewing locks correctly on Azure Service Bus
AutoRenewTimeout should always be set to longer than MaxLockDuration as it will be counterproductive to have them equal. Have it somewhat larger ...
Read more >
Azure Service Bus lock renewal - Particular Software
Message lock renewal applies to only the message currently being processed. Prefetched messages that are not handled within the LockDuration ...
Read more >
azure.servicebus package — Azure SDK for Python 2.0 ... - NET
Auto renew locks for messages and sessions using a background thread pool. It is recommended setting max_worker to a large number or passing ......
Read more >
Azure Service Bus - How to extend the lock of a message
When using Peek and Lock, by default we lock the message for 60 seconds. This means that in this time interval the message...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found