Search code examples
.netmasstransitmediator

MassTransit: Domain vs Integration events


In learning about the Mediator pattern, I came across Mass Transit. While i have a decent enough understanding of the theory ( i hope) i am struggling to find code samples / documentation that support the scenario below:

Suppose there is CustomerService (A) and NotificationService (B).

There are events raised on A that will be exclusively consumed by itself and there are events that will raised by A to be also consumed by B

In the first scenario imagine a CustomerUpgradedEvent is raised and this will be handled internally in the first service. This is what i call domain event and NewCustomerCreatedEvent that will also be handled by NotificationService (send emails, etc), which i'm calling integration event.

And herein lies my problem. Should i configure MassTransit to use rabbitMq (or any other out-of-memory bus) for the first kind of events? it seems like an overkill and potentially introducing delays /unnecessary problems (what if connection to queue dies? I know MassTransit has measures to mitigate this but still)

Can i configure MT with both in-memory and rabbitmq and have my targeted dispatching?


Solution

  • MassTransit's Mediator can be used alongside a transport-based bus.

    Using IScopedMediator or IMediator will dispatch messages immediately, whereas messages produced via IPublishEndpoint or ISendEndpointProvider will be dispatched via RabbitMQ (or whatever transport is configured).