New to Azure, I wrote an azure function that is triggered when message arrives to service bus queue. Do I need to remove this message manually or is this handled by service bus?
2 Answers
No, you don't have to remove the message manually when you're using a Service Bus trigger:
The Functions runtime receives a message in PeekLock mode. It calls
Complete
on the message if the function finishes successfully, or callsAbandon
if the function fails. If the function runs longer than thePeekLock
timeout, the lock is automatically renewed as long as the function is running.
Source: Trigger - PeekLock behavior

- 14,105
- 2
- 40
- 53
-
I've got to correct you. I had my queue remain the same when exception is thrown and not handled. So keep that in mind - in case you want to clear up the queue used by the trigger, your code must finish without unhandled exceptions. – GeorgiG Apr 14 '21 at 15:16
-
@GeorgiG if I'm not mistaking, that's exactly what the answer states. "It calls Complete on the message if the function finishes successfully, **or calls Abandon if the function fails**" – rickvdbosch May 04 '21 at 07:12
-
If Abandon leads the queue to keep the message intact, then you may need to delete it manually. I'm not arguing your quote, I'm bringing more context into the discussion. I had to repeatedly manually delete messages in case of exceptions. – GeorgiG May 05 '21 at 12:57
The messages in Service Bus can be received either in peek lock mode or receive and delete mode. When the message is received in peek lock mode,the message is not deleted from the queue.But when it is received in receive and delete mode the message is automatically received and removed from the Queue. So removing the message depends on the mode of receive you have performed Azure functions receive messages in peek-lock mode,so if the complete() is called,the message will be removed from the queue

- 333
- 2
- 12