Monday, August 6, 2018

MassTransit, a real alternative to NServiceBus?

Understand how MassTransit could be a real alternative when building distributed systems on the .NET Platform.
Photo by Markus Spiske on Unsplash

Looking for an free and open-source alternative to NServiceBus? Maybe MassTransit could be what you are looking for. Let's understand the platform and how it could be used on your next project.

What is MassTransit?

MassTransit is a lightweight service bus for building distributed .NET applications. The main goal is to provide a consistent, .NET friendly abstraction over the message transport (RabbitMQ, Azure Service Bus, etc.).

MassTransit is not a new project. They've been around since 2007 and were created as an alternative to NServiceBus. In early 2014, the framework was rewritten to support asynchronous programming as well as leveraged the power of advanced messaging platforms like RabbitMQ that since then, became the default broker. The remaining code was also rewritten, resulting in an entirely new, completely asynchronous, and highly optimized framework for message processing.

Why MassTransit

Like NServiceBus, MassTransit helps decoupling your backend from your frontend (and in general, decoupling services), leveraging enterprise design patterns like CQRS and Eventual Consistency.
Some of MassTransit's benefits are:
  • providing support for messages, sagas
  • supporting different transports
  • allows automated or custom retries on failures
  • poison message handling
  • exception management
  • custom serialization
  • message correlation
  • routing
  • scheduling


MassTransit is also extremely customizable and can run on RabbitMQ and Azure Service Bus and other cloud providers providing enormous benefits as both are strong and stable platforms with different characteristics. It also supports the new .NET Standard 2.0 on the new .NET Core framework, transforming it in truly multi-platform framework.

Sample Code

Ready to look at some code? Take a look at three examples to understand how to initialize a console hosted service.

Initting the Bus

The below code shows how to initialize a simple MassTransit Bus:

Initting a Server

The below code shows how to initialize a simple MassTransit server:

Initting a Client

The below code shows how to initialize a simple MassTransit client that talks to the above service:


I've been using NServiceBus for quite some time. While I recognize the value it adds, my frustrations with it have been growing. And on that end, MassTransit appears as a very solid alternative.

More about MassTransit?

Want to learn more about MassTransit? Please consider reading the following posts:


See Also

For more posts about MassTransit on this blog, please click here.
Do you have any comment or suggestion about this post? Please contact me @BrunoHilden