1

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?

Ariel Moraes
  • 602
  • 7
  • 15

2 Answers2

1

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.

mookid8000
  • 18,258
  • 2
  • 39
  • 63
  • Will the internal Rebus deserializer work as expected when recreating the event on the subscriber side? The sample was built using a simple string, what about complex types? – Ariel Moraes Jul 26 '18 at 15:48
  • Just created a sample to check that out, and, indeed, the deserializer tries to recreate the original type instead of just deserializing the json to the destination object. The fact is that the deserializer tries to find the type specified in $type thus the error: Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON 'RabbitRebusTests.Producer.TextMessage, RabbitRebusTests.Producer'. – Ariel Moraes Jul 26 '18 at 16:48
  • Changed the sample to use specific JsonSerializationSettings without the TypeNameHandling, but now I'm getting the error _Message with ID 00f088ed-4448-47b0-8221-e9884fb9ff70 and type RabbitRebusTests.Producer.TextMessage, RabbitRebusTests.Producer could not be dispatched to any handlers_ on the consumer. – Ariel Moraes Jul 26 '18 at 17:21
0

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

Karan
  • 65
  • 5