1

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?

Timsen
  • 4,066
  • 10
  • 59
  • 117

2 Answers2

4

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.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • But then each message will be processed twice, because in topics all the subscribers receive same message, or did I misunderstood something? – Timsen Dec 04 '17 at 13:54
  • Depends on you. For each subscription you can create a filter, which will restrict which messages go through. Read "Rules and actions" section in the doc. – Mikhail Shilkov Dec 04 '17 at 13:59
  • Right. that's the main design point. the topic gets created.....with multiple subscribers, and the subscribers (through rules) can decided if they are or are not interested in the message. Put a custom property on your messages based on your "Types" and then use rules based on this custom property value. – granadaCoder Aug 20 '19 at 19:46
0

How different are the different message types from each other?

You could possibly set up 4 different topics, one for each message type. The listeners would only need to listen to the topics that they are interested in.

This may be overkill if the message body for each message type is basically the same.

Dave
  • 3,676
  • 4
  • 28
  • 39