Skip to main content

Posts

Showing posts with the label WebJobs

How to use the same QueueTrigger method for reading/handling messages from different Azure Message Queues using INameResolver

The Azure WebJob SDK provides a lot of helper functionalities that we can leverage. One example is the QueueTrigger API, that provides the ability to read messages from a queue when a message comes in. Just as a comparison, if you are not using the QueueTrigger API, you will probably have to write some timer, and/or loop code to read messages from a queue periodically. This is not fun. Let's take a look at a usage example below. public class Foo { ... public void ProcessMessage([QueueTrigger("MyQueueName")] string message) { // Do something with message. ... } The code above is pretty self explanatory. This class will be invoked when a message appears on "MyQueueName". However, what if we want to handle a bunch of messages coming from different queue names? Would we have to repeat this code in a couple of places? Certainly not! We can handle this by implementing INameResolver. public class NameRe...