How to subscribe to Events without coupling the Event Type from another project using Rebus?

252 Views Asked by At

I have several microservices and many of them have Integration Events. Imagine a microservice M1 that needs to subscribe to an event that lies in the microservice M2. How can I subscribe to the event without coupling the M2 and M1? Is there another way to subscribe without using the event type instead use the event name for example?

2

There are 2 best solutions below

0
On

There are two ways ( depending on your need) which can be used to address this scenario first it to IHandleMessages and handle for dynamic object second is by providing implementation of ISerilizable we used the second option.

Further read: https://github.com/rebus-org/Rebus/issues/24

3
On

While Rebus encourages the use of type-based topics, the underlying mechanism is based on simple string-based topic names.

The "raw topics" mechanism is available via bus.Advanced.Topics, so you can

await bus.Advanced.Topics.Subscribe("whatever");

to subscribe to the whatever topic, and then you can

await bus.Advanced.Topics.Publish("whatever", yourEvent);

to publish events to that topic.

The RabbitMQ Topics sample demonstrates how it can be done, and it even shows how RabbitMQ's underlying topic wildcards can be used this way.