How domain events can be communicated (published / subscribed) across bounded context

619 Views Asked by At

An open host service is a way of mapping between contexts that is appropriate for cases where you would expose access via APIs. What is a good way to represent a mapping beween contexts, where you intend to publish / consume domain events?

1

There are 1 best solutions below

1
On

How to interact across bounded context when domain events occurs in the system ?

Interacting via events is a very powerful way to develop the application. Once you get used to this you will feel very easy and convenient way to interact within and across systems (depending on the business needs).

Let us consider you have two bounded context context-A and context-B respectively. In bounded context-A based on certain business logic in domain model you want to notify the other bounded context-B to take certain action.

In this case after executing your business logic in domain model. You can create an domain event from your domain service and let your application service (which is local to your bounded context in this case context-A) manage to fire an Domain Event to the publisher with help of your infrastructure layer. Now the publisher can store this event in the Event Store and then forward to the Messaging Queue.

The Subscriber in bounded context-B can make arrangements to listen to the events on bus and take required action to be executed.

Thus how in domain driven design we can organise to publish or subscribe to the domain events.

  • If bounded context is in two different code base/projects its always good to use Event store and Message queue
  • If its in the same code base you can manage to common publisher and subscriber which helps to mange domain events.

Hope this high level explanation may help.