Redbus 1.0.8

A simple in memory EventBus / MessageBus library in C#

Install-Package Redbus -Version 1.0.8
dotnet add package Redbus --version 1.0.8
<PackageReference Include="Redbus" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Redbus --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Redbus, 1.0.8"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Redbus as a Cake Addin
#addin nuget:?package=Redbus&version=1.0.8

// Install Redbus as a Cake Tool
#tool nuget:?package=Redbus&version=1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

RedBus

A simple in memory EventBus / MessageBus library in C# with no dependencies

Build status

Nuget

Install-Package Redbus 

NuGet

Supported Frameworks

  • .NET Framework 4.5
  • .NET Standard 2.0

Example Usage

There is a generic PayloadEvent class that can be used, or you can use any custom classes that derive from EventBase


private void TestMethod()
{
  IEventBus eventBus = new EventBus();
  eventBus.Subscribe<PayloadEvent<int>>(OnIntEvent); 
  eventBus.Subscribe<CustomEventClass>(OnCustomEvent); 
  
  eventBus.Publish(new PayloadEvent<int>(5)); // OnIntEvent will be invoked
  eventBus.Publish(new CustomEventClass()); // OnCustomEvent will be invoked
  
  
  eventBus.Subscribe<PayloadEvent<string>>(s =>
  {
    Console.WriteLine(s.Payload);
  });
  
  eventBus.Publish(new PayloadEvent<string>("Hello"));
}

private void OnCustomEvent(CustomEventClass customEvent)
{
  Console.WriteLine("Received CustomEvent");
}

private void OnIntEvent(PayloadEvent<int> intEvent)
{
  Console.WriteLine(intEvent.Payload);
}

Note that RedBus does not have WeakReferences implemented, so you must explicitly call Unsubscribe for the event when disposing
the subscriber to avoid memory leaks. The Subscribe method returns a SubscriptionToken, this is used when unsubscribing.


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

eventBus.Unsubscribe(token);

Extensions


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

token.Unsubscribe(eventBus)

var payloadEvent = new PayloadEvent<string>("Hello");
payloadEvent.Publish(eventBus);

Configuration

  • ThrowSubscriberException

By default, Redbus will catch and swallow any exceptions thrown by subscribers.
It's possible to configure Redbus to rethrow any exceptions which occurred in a subscriber method - please note the following:

  • This will cause an exception from a subscriber to be thrown for a publisher
  • This will/may cause subsequent subscribers to not receive an event/message after a subscriber has thrown an exception.

IEventBus eventBus = new EventBus(new EventBusConfiguration { ThrowSubscriberException = true });

RedBus

A simple in memory EventBus / MessageBus library in C# with no dependencies

Build status

Nuget

Install-Package Redbus 

NuGet

Supported Frameworks

  • .NET Framework 4.5
  • .NET Standard 2.0

Example Usage

There is a generic PayloadEvent class that can be used, or you can use any custom classes that derive from EventBase


private void TestMethod()
{
  IEventBus eventBus = new EventBus();
  eventBus.Subscribe<PayloadEvent<int>>(OnIntEvent); 
  eventBus.Subscribe<CustomEventClass>(OnCustomEvent); 
  
  eventBus.Publish(new PayloadEvent<int>(5)); // OnIntEvent will be invoked
  eventBus.Publish(new CustomEventClass()); // OnCustomEvent will be invoked
  
  
  eventBus.Subscribe<PayloadEvent<string>>(s =>
  {
    Console.WriteLine(s.Payload);
  });
  
  eventBus.Publish(new PayloadEvent<string>("Hello"));
}

private void OnCustomEvent(CustomEventClass customEvent)
{
  Console.WriteLine("Received CustomEvent");
}

private void OnIntEvent(PayloadEvent<int> intEvent)
{
  Console.WriteLine(intEvent.Payload);
}

Note that RedBus does not have WeakReferences implemented, so you must explicitly call Unsubscribe for the event when disposing
the subscriber to avoid memory leaks. The Subscribe method returns a SubscriptionToken, this is used when unsubscribing.


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

eventBus.Unsubscribe(token);

Extensions


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

token.Unsubscribe(eventBus)

var payloadEvent = new PayloadEvent<string>("Hello");
payloadEvent.Publish(eventBus);

Configuration

  • ThrowSubscriberException

By default, Redbus will catch and swallow any exceptions thrown by subscribers.
It's possible to configure Redbus to rethrow any exceptions which occurred in a subscriber method - please note the following:

  • This will cause an exception from a subscriber to be thrown for a publisher
  • This will/may cause subsequent subscribers to not receive an event/message after a subscriber has thrown an exception.

IEventBus eventBus = new EventBus(new EventBusConfiguration { ThrowSubscriberException = true });

  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.8 12,837 8/20/2019
1.0.7 778 6/10/2019
1.0.6 383 4/24/2019
1.0.5 4,880 8/9/2018
1.0.4 1,962 10/24/2017
1.0.3 1,480 3/31/2017
1.0.2 3,380 12/19/2015
1.0.0 792 12/19/2015