3

I have implemented a long running process as a WebJob using the WebJobs SDK. The long running process is awaited because I want the result.

public async Task ProcessMessage([ServiceBusTrigger("queuename")] MyMessage message)
{
    await Run(message.SomeProperty); // takes several minutes
    // I want to do something with the result here later..
}

What I can't figure out is why the message sometimes is abandoned which of course triggers the handler again. I've tried to debug (locally), setting breakpoints before ProcessMessage finishes and I can see that it appears to finish successfully.

The Sevice Bus part of the WebJobs SDK takes care of message lock renewal, so that shouldn't be a problem as far as I've understood.

What am I missing and how do I troubleshoot?

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
Anton
  • 1,346
  • 11
  • 31

1 Answers1

5

[Edited previously incorrect response]

The WebJobs SDK relies on the automatic lock renewals done by MessageReceiver.OnMessageAsync. These renewals are governed by the OnMessageOptions.AutoRenewTimeout setting, which can be configured like so in the v1.1.0 release of the WebJobs SDK:

JobHostConfiguration config = new JobHostConfiguration();

ServiceBusConfiguration sbConfig = new ServiceBusConfiguration();
sbConfig.OnMessageOptions = new OnMessageOptions
{
  MaxConcurrentCalls = 16,
  AutoRenewTimeout = TimeSpan.FromMinutes(10)
};

config.UseServiceBus(sbConfig);

You can also customize these values via a custom MessageProcessor. See the release notes here for more details on these new features.

mathewc
  • 13,312
  • 2
  • 45
  • 53
  • 2
    On further investigation, while the ServiceBus documentation is very poor, it does appear that OnMessageAsync does do automatic renewals. Try configuring the **OnMessageOptions.AutoRenewTimeout** value and increase it for your scenarios. See the ServiceBus documentation on that setting [here](http://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.onmessageoptions.autorenewtimeout.aspx). The ability to configure this was only recently added to the WebJobsSDK. See ServiceBusConfiguration.OnMessageOptions. – mathewc Oct 29 '15 at 16:08
  • 1
    Looks like that is the way to go. Full package name for Googlers: Microsoft.Azure.WebJobs.ServiceBus 1.1.0-beta1 (Pre-release channel, that is). Thanks for the update! – Anton Oct 29 '15 at 17:46