How to create a single NServiceBus endpoint that uses different transports?

Background

We are trying to introduce a new architectural model in our company and are considering CQRS using Event Sourcing using a service bus. The technologies we are currently developing our POC with are NServiceBus, Event Store, and MSMQ. We would like to have a single endpoint in NServiceBus defined by two different vehicles, MSMQ for our teams and the Event Store for our events. The current state of our enterprise does not allow us to easily switch everything to the Event Store at present, because we have significant investments in our legacy applications using MSMQ, which is the reason that we are considering a hybrid approach.

Question

Is it possible to create a single NServiceBus endpoint that uses different transports? If so, how? If not, what are the alternatives?

+5
source share
1 answer

Aaron

I think the best option would be to use MSMQ as a transport in NServiceBus. Here's what it might look like:

  • send command via MSMQ
  • in the command handler (re) creates an aggregate, which is the purpose of the command
  • invoke operations
  • save received events in EventStore along with the team message identifier to ensure idempotence. The unit itself will be responsible for knowing already processed teams.
  • in a separate component (event processor) they use the EventStore persistent API to bind to the entire stream of events. Some of these processed events should result in a command being sent. Such a command can be sent through the NServiceBus send endpoint located inside this event processor.
  • in this event processor, you can also republish all events through NServiceBus and MSMQ. Such events should not be subscribed by other services (see Note on autonomy below).
  • NServiceBus Sagas (process managers) must live within the boundaries of your service and respond to commands and / or events sent or republished by these event processors via MSMQ.

One of the remarks regarding service boundaries is that you need to decide what level of service autonomy suits you: * Weak ones, where services can directly subscribe to other service event flows. In these design events that cross the service boundary, it is obviously allowed to carry data. * Strong, where services use events of a higher level for communication, and these events carry only the identity of things and there is no data . If you want something like this, you can use event processors to map ES events to these higher-level events.

+3
source

All Articles