Libin Joseph Libin Joseph - 1 month ago 16
C# Question

Azure Service Bus Queue

I like to add azure service bus to one my projects. And the project does a few different tasks: sending email, processing orders, sending invoices etc.

What I am keen to know is, do I create seperate queues to process all these different tasks ? I understand that a queue has one sender and one reciever. That makes sense, but then I will end up with quite a few number of queues for a project. is that normal?

Answer

Based on your description:

The project does a few different tasks: sending email, processing orders, sending invoices etc.

These messages are not related to each other. I like to differentiate between commands and events. Commands are sent specifically to certain destination with an expectation of an outcome, knowing that operation could fail. With events it's different. Events are broadcasted and there are no expectations for success or failure. There's also no knowledge about consumers of events to allow complete decoupling. Events can only be handled using Topics/Subscriptions. Commands can be handled either with Queues or with Topics/Subscriptions (a topic with a single subscription would act as a queue).

If you go with events, you don't create separate consumer input queues. You create a topic and subscriptions on that topic. Let's say you'll have a PublisherApp and a ConsumerApp. PublisherApp could create a topic and send all messages to the events topic. ConsumerApp would create the required subscriptions, where each subscription would have a filter based on type of the message you'd like that subscription to receive. For your sample, it would be the following subscriptions:

  1. SendMail
  2. ProcessOrder
  3. SendInvoice

In order to filter properly, your BrokeredMessages will have to have a header (property) that would indicate the intent. You could either come up with a custom header or use a standard one, like Label.

I wrote a blog post a while ago on topologies with ASB, have a look, it might give you more ideas on how you can set up your entities.

If topology & entities management is not what you'd like to do, there are good frameworks that can abstract it for your and allow your code to work w/o diving into details too much. NServiceBus and MassTransit are two good examples you can have a look at.

Full disclosure: I'm working on Azure Service Bus transport for NServiceBus.

Comments