Skip to content

Ralstlin/ArqueBus

Repository files navigation

ArqueBus

ArqueBus is a .Net core generic memory event bus.

Build Build status
Tests Tests status
Coverage SonarCloud Coverage
Quality Quality Gate SonarCloud Bugs SonarCloud Vulnerabilities
Nuget Nuget Nuget

Usage

The way to create a bus is really simple, just new EventBus<T, TModel>(); where

  • T is the type used to find the subscription!
  • TModel is the type for the objects passed by the publications, you can use object, a base class or implement an interface for your models.

Simple Subscribe/Publish:

var eventBus = new EventBus<string, IModel>();

eventBus.Subscribe("test.first", (data) =>
{
  Console.WriteLine(data.StringValue);
});

underTest.Publish("test.first", new Model(){StringValue = "my.string"});

Awaiting publications and receiving the models published:

// Create new event bus
var eventBus = new EventBus<string, object>();

// Listen for publications
var options = new DataflowBlockOptions { CancellationToken = cancellationTokenSource.Token };
var listenedTask = eventBus.ListenAsync<string>("test.first", options);

// publish something
eventBus.Publish("test.first", "published-string-1");
eventBus.Publish("test.first", "published-string-2");

// Cancel listening for publications or awaiting listnedTask will hang forever.
cancellationTokenSource.Cancel();

//Get data
var result = await listenedTask;
Console.Writeline(result.Skip(0).First()) // published-string-1
Console.Writeline(result.Skip(1).First()) // published-string-2

About

.netstandard2.0 generic memory event bus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages