title: Azure ServiceBus AutoRenewTimeout
body: <p>I am using Azure ServiceBus Queues through the .net SDK. There is a flag on the OnMessageHandler/OnMessageOptions called "AutoRenewTimeout", but there seems to be confusion on what this value actually means. </p>
  
  <p>On the official documentation here <a href="https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.onmessageoptions.aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.onmessageoptions.aspx</a> it suggests that the AutoRenewTimeout should be greater than the queue lockduration. </p>
  
  <blockquote>
    <p>Gets or sets the maximum duration within which the lock will be renewed automatically. This value should be greater than the longest message lock duration; for example, the LockDuration Property. </p>
  </blockquote>
  
  <p>This seems to suggest that the AutoRenewTimeout is more or less the maximum time that it should take to process a message. e.g. If you have a lock duration of 1 minute, and an autorenewtimeout of 5 minutes, the message will be renewed a total of 5 times before giving up and making it visible on the queue again. There is also other StackOverflow answers confirming this to be the case  e.g. <a href="https://stackoverflow.com/a/36051408">https://stackoverflow.com/a/36051408</a></p>
  
  <blockquote>
    <p>To handle long message processing you should set AutoRenewTimeout == 10 min (in your case). That means that lock will be renewed during these 10 minutes each time when LockDuration is expired.</p>
    
    <p>So if for example your LockDuration is 3 minutes and AutoRenewTimeout is 10 minutes then every 3 minute lock will be automatically renewed (after 3 min, 6 min and 9 min) and lock will be automatically released after 12 minutes since message was consumed.</p>
  </blockquote>
  
  <p>However on more research, I stumbled upon an old tweet (<a href="https://twitter.com/clemensv/status/649940087267041284" rel="noreferrer">https://twitter.com/clemensv/status/649940087267041284</a>) by what looks to be the Lead Architect for Messaging at Microsoft. In this tweet it seems to suggest that AutoRenewTimeout is instead the interval in which it will call the "RenewLock" method. </p>
  
  <blockquote>
    <p>it's the interval in which <a href="https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.brokeredmessage.renewlock.aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/microsoft.servicebus.messaging.brokeredmessage.renewlock.aspx</a> is called on a message while the callback is active</p>
  </blockquote>
  
  <p>So for example if your lockduration is 1 minute, the AutoRenewTimeout should be something like 30 seconds to ensure that the message lock is renewed before it gets released. </p>
  
  <p>In my own tests, I'm leaning towards the former being correct, but the tweet is making me suspicious on the fact maybe I don't know the full use of AutoRenewTimeout</p>