Rebus .NET Service Bus
repository·master·Indexed 25 days ago
https://github.com/rebus-org/rebusA lightweight, lean service bus for .NET designed for asynchronous messaging between microservices using the 'smart endpoints, dumb pipes' pattern. It targets .NET Standard 2.0, supporting .NET Framework 4.6.1, .NET Core 2, and .NET 5+. Features include a fluent configuration API, type-based routing, and support for various transports.
What's inside Rebus
- Rebus is a lean service bus implementation for .NET designed as 'dumb pipes' for asynchronous communication in microservices. It follows the 'smart endpoints, dumb pipes' principle and aims to provide a simple, intuitive configuration experience with minimal dependencies (primarily JSON.NET). It targets .NET Standard 2.0, supporting .NET Framework 4.6.1, .NET Core 2, and .NET 5+.
Initialize Rebus manually with RebusBus
masterFor manual control, you can instantiate the
RebusBusclass directly by providing the necessary dependencies. You must call.Start(int workerThreads)to begin processing and ensure you call.Dispose()when the application exits to clean up resources.var bus = new RebusBus(...); bus.Start(1); //< 1 worker thread // use the bus for the duration of the application lifetime // remember to dispose the bus when your application exits bus.Dispose();Configure Rebus using the Fluent API
masterThe recommended way to set up Rebus is using the
Configure.With(...)fluent API. You can use the built-inBuiltinHandlerActivatoror integrate your own IoC container using an adapter. Once configured, Rebus registers theIBusinstance (typically as a singleton) and uses the container to resolve message handlers.var someContainerAdapter = new BuiltinHandlerActivator(); Configure.With(someContainerAdapter) .Logging(l => l.Serilog()) .Transport(t => t.UseMsmq("myInputQueue")) .Routing(r => r.TypeBased().MapAssemblyOf<SomeMessageType>("anotherInputQueue")) .Start(); // have IBus injected in application services for the duration of the application lifetime // let the container dispose the bus when your application exits myFavoriteIocContainer.Dispose();Configure Type-Based Routing by Namespace
masterWhen using type-based routing, you can restrict the mapping to a specific namespace instead of an entire assembly. This is useful if the assembly contains shared code that should not be routed through a specific queue.
Configure.With(someContainerAdapter) .(...) .Routing(r => r.TypeBased().MapAssemblyNamespaceOf<SomeMessageType>("namespaceInputQueue")) .(...); // have IBus injected in application services for the duration of the application lifetime // let the container dispose the bus when your application exits myFavoriteIocContainer.Dispose();