Search code examples
queueazureservicebusservicebusazure-servicebus-queues

Different readers on same service bus queue?


Lets say we have 4 different kind of messages: Type1, Type2, Type3 and Type 4.

We have a service bus queue with sessions because of nessesaty of FIFO functionality.

We also have two message writers. First message writer takes care of creating messages of type type1 and type2, where writer #2 takes care of creating messages of type type3 and type4. This is the easy part.

Now i want to be able to create two readers, reader1 and reader2.

Reader1 must read messages of type type1 and type2. Reader2 must read messages of type type3 and type4.

But i cant figure out how to achieve this. Because if reader1 reades message of type3, it needs to abanadon it, since reader1 cant only take care of messages of type type1 and type2. In worst case reader1 will be stuck with the message until it is thrown to deadletter queue.

Reason to create two different readers is because they are in two completly different domains, with completly different functionality.

How can i achieve the requered functionality?


Solution

  • You need to use Service Bus Topics and Subscriptions for this.

    Writers publish messages to a Topic. Then both readers subscribe to that topic, and each subscription can filter based on message type.

    See "Topics and subscriptions" in the docs.