I received an email from our Scott Densmore earlier this week that pointed me to a GIT project which had some updates he was making to PnP Azure guidance. Without pressing F5, I started my own code review on the solution to see how the code was laid out. Here’s the post that discussed the changes, and here’s the GIT source he posted.
He mentioned a MultiEntity pattern he was plugging in based on another post. Both posts was interesting, and made total sense to a Azure noob like me. Hanselman is big on reading good code, and today I read some really good code. How do I know? I compared it to some Azure Boot Camp code that laid out a short talk on Azure Queues today, which is where I focused my review. From there, I went back up the stack to the data services (Role, Member, Session) and dove into the decoupled plumbing code from there, then up to the ASP providers.
This discussion about queue processing, not the MultiEntity pattern, Scott nails that together, and if that doesn’t do it for you, check out the article Scott references in his post.
The interesting difference in from the boot camp code was how the worker role that managed the queues was working. The PnP code had setup a Task to run the job at specific intervals with an object called QueueCommandHandler that handles the processing. Here was the difference. The boot camp code looked at using while(true) to loop through the queues’ messages to process. I will have to say, the boot camp webcast definitely helped me understand queue processing much-much better. And I could read through the PnP code even more easily.
The generic command queue handler which the queue command handler derives from looks like this:
The queue command handler looks like this:
The command handler looks like this:
When the worker role starts, it handles task scheduling like this for queue and non-queue command processing:
The Do() still uses a loop to process, but the processing is still pulled apart and re-usable a bit more to my liking.
The only thing I would to differently at first glance at all of this code was to incorporate some type of rheostat to handling slowing the processing if the queues are so busy.
The boot camp web cast had an interesting approach to this called exponential back-off polling when means to us mortals is that if I look at queue every 5 seconds and it’s empty, I’m going to set an interval somewhere to 10 seconds so I check less often.
I’ve built things like this into some projects I’ve built, and usually from configuration, but this needs to be more dynamic (hands-free). I’ll probably toy with this to build something easier to ready (which is why I’m not posting it here).
Take a look at Scott’s code and pick out some part of Azure that interests you as see if there any queues you want to take from their guidance.