Sample code on how to move all queue items on to another queue in Azure Functions.
Here is the link to the article on hashnode or dev.to.
The repo is a standard Azure Function App and you can run it locally (interact with it using Postman).
- Azure Function Core Tools.
- Azure Storage Emulator.
- Azure Storage Explorer.
- Start the Azure Function App.
- Run
PopulateSourceQueuehttp trigger, to put sample items on the queue. - The queue trigger
TriggerSourceQueueToFail, will process the queue items, while also raising an exception to simulate an error that will cause the queue items to move on to the poison queue. - Check with Azure Storage Explorer that the queue named main-queue-poison has items in it.
- Stop the Azure Function App.
- Comment out
throw new Exception("simulating a process failure for a dequeue to poison queue");inTriggerSourceQueueToFail.cs, to simulate that no error is raised while processing queue items. - Restart the Azure Function App.
- Use either of the time trigger
RequeueUsingDIorRequeueUsingStaticto requeue the items from poison queue back to the main queue. - The queue trigger
TriggerSourceQueueToFailwill run again, this time the queue items will be processed and both main-queue and main-queue-poison should be empty.
One of the Time trigger RequeueUsingDI or RequeueUsingStatic can only be active at a time, they do same task, and you don't want both to be running at the same time. They are in the repo to illustrate that requeue-ing can be done with either Dependency Injection (DI) or Static azure function.