I am working on a command processing application which uses azure service bus queue. Commands are issued from a website and posted to the queue and the queue messages are processed by a worker role. Processing involves fetching data from db and other sources based on the queue message values and sending it to different topics. The flow is ,
- Receive message
- process the message
- Mark message as complete / Abandon message On processing exception.
The challenge I face here is the processing time. Sometimes it exceeds the maximum message lock time period (5 minutes -configured) and hence the message is unlocked and it re-appears for the worker role to pick up (consider multiple instances of the worker role). So this causes same message to be processed again.
What are the options I have to handle such a scenario.?
I have thought about ,
Receive message - add to a local variable - mark message complete. In case of exception send the message again to the queue or to a separate queue (let us say failed message queue). A second queue also means another worker role to process it.
In the processing there is a foreach loop that runs. So I thought of using a Parallel.Foreach instead . but not sure how much of time gain it will give and also read some posts on issues when using Parallel in azure.
Suggestions,fixes welcome.