Rebus .NET Service Bus

repository·master·Indexed 25 days ago

https://github.com/rebus-org/rebus

A 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.

Tokens
828
Snippets
3
Records
4
Agent score
33%

What's inside Rebus

  1. Overview of Rebus

    master
    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+.
  2. Initialize Rebus manually with RebusBus

    master

    For manual control, you can instantiate the RebusBus class 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();
  3. Configure Rebus using the Fluent API

    master

    The recommended way to set up Rebus is using the Configure.With(...) fluent API. You can use the built-in BuiltinHandlerActivator or integrate your own IoC container using an adapter. Once configured, Rebus registers the IBus instance (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();
  4. Configure Type-Based Routing by Namespace

    master

    When 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();