0

I'm having an issue where I'm triggering an event which is being handled by an Azure Function Service Bus Trigger.

The trigger that runs could run for anywhere up to an hour which is fine but I'm finding that after 5 minutes the message gets re added to the queue, so it's getting handled repeatedly.

I can hack around this by ensuring that this specific topic will only read the message once by changing the MaxDeliveryCount but ideally I'd like the lock to have a longer expiry time than the function (max 1 hour).

According to the Microsoft Documentation it should already do this but I'm still getting the issue when it's re queueing the message.

The Functions runtime receives a message in PeekLock mode. It calls Complete on the message if the function finishes successfully, or calls Abandon if the function fails. If the function runs longer than the PeekLock timeout, the lock is automatically renewed as long as the function is running.

Any ideas?

scottdavidwalker
  • 1,118
  • 1
  • 12
  • 30

1 Answers1

2

Azure Service Bus can only lock a message for a maximum of 5 minutes at a time. But it can also renew the lock, which, technically, can allow messages to be locked for as long as needed as long as there are no failures to issue the locking requests. In addition to that, there's a limit on the execution time functions can have. For example, on the Consumption plan, a function won't run longer than the maximum 10 minutes. For any processing longer than that, one should either look into alternatives, that include but are not limited to the following:

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • It's a durable function so it should be able to run as long as necessary. The question is, how do I auto renew the lock or is this something done by Azure on their side? – scottdavidwalker Nov 19 '21 at 08:59
  • 1
    Durable functions are not magic. And it ain't free to run w/o any limits. So I highly doubt your assumption about execution time. Nonetheless, `host.json` is where you would specify the max lock renewal value. – Sean Feldman Nov 19 '21 at 09:05
  • So the only options that I'm seeing is "maxAutoRenewDuration". The docs say " The maximum duration within which the message lock will be renewed automatically.". So would this mean that I specify this time lower than the lock time or at a maximum running time of the function? Sorry for the questions, I'm new to Service Bus but I really appreciate the help – scottdavidwalker Nov 19 '21 at 10:28
  • Actually, I think this comment explains it quite well. https://github.com/Azure/azure-functions-host/issues/6500#issuecomment-676613727 – scottdavidwalker Nov 19 '21 at 10:34
  • 1
    Yep. You always set "relock" to be longer than the conventional max lock duration. Otherwise it makes no sense tbh. – Sean Feldman Nov 19 '21 at 14:36