简体   繁体   中英

Azure Function and storage queue

I try to use Azure Storage Queue with azure function and I imagined it as very simple - get message from queue, processing, add new if necessary. But right now I get a mess, messages readd during my function processing current message (I have long process), sometimes I see messages in queue, which processed long time ago.

Any way to say Azure Function:

  1. Get message and delete from queue
  2. Processing message
  3. If success - nothing happened, if failure (exception) - readd current.

Nothing more. Without any complex logic. Is it possible?

Based on comments above

Your function is triggered by message in service bus. You process the message. If you are happy and done in the given execution time (5 mins default) then message is marked as completed. If you are not happy , throw the exception. The function will consider message not completed and abandon it so it re-appears in the queue , however you retry count will keep on growing until it reaches the max value after which message is sent to dead letter queue.

Couple of points to note

If you don't throw the exception and process does it itself (due to some processing error) it still considers it abandoned message and will retry . However if function executes successfully without throwing any error but result is not what you want then throw ex your self.

Also in services bus increase the lock time to match the processing time of your function. eg function takes 5 mins to complete , but your message lock time in your services bus is 30 secs , the message will reappear in message queue while the other copy of message is still being processed by function. So increase your services bus message lock time that you consider is sufficient for function to complete the process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM