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.

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.

MassTransit's Benefits

Like NServiceBus, MassTransit helps decoupling your backend from your frontend (and in general, decoupling services), leveraging enterprise design patterns like CQRS and Eventual Consistency.

MassTransit benefits include:
  • 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
  • and more...

MassTransit is also extremely customizable and can run (as of July 2018) on RabbitMQ and Azure Service Bus which is an 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? I also have tested it in different scenarios with very positive results. Here are some of my experiences

The MassTransit GitHub Repo has many interesting samples including:

Conclusion

I've been using NServiceBus for quite some time. While I like it and recognize the value it adds, I miss open alternatives to it in the .NET ecosystem. MassTransit appears to be a very robust and mature framework and I'm excited to try it out in production.

See Also

Creating a MassTransit client/server application using RabbitMQ, .Net Core and Linux
Exploring MassTransit InMemory Scheduled Messaging using RabbitMQ and .Net CoreCustom Security on NserviceBus Endpoints
Why you should start using .NET Core
Building and Running ASP.NET Core apps on Linux
.NET Core and .NET merging as .NET 5.0
Package Management in .NET Core

For more posts on MassTransit, please click here.

References

MassTransit - Project
MassTransit - GitHub
MassTransit - Nuget.org
Ben Morris: Comparing nServiceBus and MassTransit: Do we still need .Net integration frameworks?