Initially I thought you could see a Topic as a Microservice. For example you could have the following Topics:
- OrderTopic
- InvoiceTopic
When an application publishes an "event" like: ProductOrderedEvent
, that all Topics interested in this event could subscribe to it. So that it would sort of looked like this:
- OrderTopic
- ProductOrderedEvent
- SomeOtherEvent
- InvoiceTopic
- ProductOrderedEvent
- SomeOtherInvoiceEvent
- etc.
But when I try to publish an event (or Message rather), then I have to name the topic explicitly to which I want to publish the event to. So I guess my view on the term "Topic" is wrong.
I simply wanted to group by code by context. Everything about products should live in the ProductsTopic
, everything about orders should live in the OrdersTopic
etc.
But I don't want to name each topic explicitly in my code. I just want to publish an event, and the subscribers in what ever topic that are interested in this event should be able to pick this event up.
Is it possible to publish an event/message to simply ALL topics without explicitly naming them? Or should I simply name my topic "MyOrganizationName" and put all subscribers in there?
While you can't send a message to a topic without naming the topic, you could however have a "catch-all" topic, subscriptions with topic filters and the forward messages to different chained entities as required.
To your example, you would have the following setup instead
So, all your applications would send messages into
CatchAllTopic
, on which each subscription filters required messages and forwards them to their respective topic.Do read the considerations to consider when using auto-forwarding.