3

I want to integrate two bounded contexts via events raised by Context A and consume the Events from Context B. How ever i want to avoid compile time dependency, so Context B does not have to include dll's/libraries of Context A. (At least i don't want the hassle of needing to update a reference to A every time a new Event type gets exposed by Context A.

Is there any prefered/best practice to do this with Rebus?

1 Answers1

1

There's a couple of ways, actually :)

Myself, I prefer to distribute the messages as separate NuGet packages – then it becomes a matter of looking into packages.config to see which dependencies each endpoint has.

As long as I keep published message schemas immutable (i.e. follow a strict append-only approach to evolving it), there's no problem in consuming events – the data is simply truncated when deserializing into an old version of the message schema.

But if you want your endpoints to be less coupled than that, you can do a couple of things.

Unless you change the serializer, the messages are serialized as UTF8-encoded JSON. This means that a subscriber can always install its own JSON serializer, that could e.g. deserialize the message to its own types, or simply into a JObject (assuming you are using Newtonsoft JSON.NET).

In fact – if I recall correctly – you can include the NuGet package Rebus.NewtonsoftJson and use it by going

Configure.With(new CastleWindsorContainerAdapter(container))
    .(...)
    .Serialization(s => s.UseNewtonsoftJson())
    .Start();

which brings with it Newtonsoft's JObject into the mix, which you can then use in your message handler by implementing IHandleMessages<JObject>.

I hope that gives you some inspiration :)

mookid8000
  • 18,258
  • 2
  • 39
  • 63