Search code examples
rebus

Rebus node acting simultaneously as competing consumer and pub-sub subscriber


I've a scenario where there is a set of nodes (N1, N2, N3) that must simultaneously

  • Subscribe to a message type T1 in a pub-sub way, i.e., any published T1 must be delivered to all nodes in the set (N1, N2 and N3)

  • Operate as a competing consumer in this set for a message type T2, i.e., any published T2 must be delivered to only one node of the set

I know how to do this using two buses

  • The first bus (for pub-sub) uses a per-node input queue.

  • The second bus (for competing consumers) uses a single input queue, shared by all nodes.

However, is there a way to avoid having two buses and accomplished the same behaviour using only one bus?

Thanks


Solution

  • As far as I can tell, you have two options:

    1) Have two bus instances in each node, where the subscribers each have their own input queue and the competing consumers all use the same queue (exactly as you described it), or

    2) Have a subscriber in each node, each using its own queue, and then manually route T2 to one of the subscribers.

    Without knowing anything about the problems you are solving, my initial thought is that (1) would be simpler and easier to get right. (2) could be fun though :)

    If you choose to do (2), it would be fun to see if e.g. the subscribers could simply subscribe to T2 as they would otherwise have done if it was a regular event, but then the producer would - instead of publishing T2 - look up the subscribers to that message and simply pick one of them.