Marille 0.3.8

dotnet add package Marille --version 0.3.8
NuGet\Install-Package Marille -Version 0.3.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Marille" Version="0.3.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Marille --version 0.3.8
#r "nuget: Marille, 0.3.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Marille as a Cake Addin
#addin nuget:?package=Marille&version=0.3.8

// Install Marille as a Cake Tool
#tool nuget:?package=Marille&version=0.3.8

marille

Marille is thin layer on top of System.Threading.Channels that provides a in-process publisher/subscriber hub.

The aim of the library is to simplify the management of several Channels<T> within an application. The general idea is that users can create different "topics" that will later be divided in subtopics based on the type of messages that they distribute. The normal pattern for usage is as follows:

  1. Create a topic, which is a pair of a topic name and a type of messages.
  2. Add 1 or more workers which will be used to consume events.
  3. Use the Hub to publish events to a topic.
  4. Workers will pick the messages and consume them based on the topic strategy that was chosen.

You can think about Marille as an in-process pub/sub similar to a distributed queue with the difference that the constraints are much simpler. Working within the same process makes dealing with failure much easier.

The library does not impose any thread usage and it fully relies on the default TaskScheduler used in the application, that is, there are no Task.Run calls to be found in the source of the library.

Examples

Here are some examples of the API usage:

Single Publisher/Worker

In this pattern we will create a single topic with a unique consumer. The Hub will only send messages to the registered consumer.

  1. Declare your consumer implementation:
// define a message type to consumer
public record struct MyMessage (string Id, string Operation, int Value);

// create a worker type with the minimum implementation 
class MyWorker : IWorker<MyMessage> {
    // Workers will be scheduled by the default TaskScheduler from dotnet
    public Task ConsumeAsync (WorkQueuesEvent message, CancellationToken cancellationToken = default)
       => Task.FromResult (Completion.TrySetResult(true));
}

  1. Setup the topic via a new Hub:

private Hub _hub;

public Task CreateChannels () {
    _hub = new Hub ();
    // configuration to be used to create the topic
    var configuration = new() { Mode = ChannelDeliveryMode.AtMostOnce };
    var topic = "topic";
    var worker = new MyWorker ();
    // workers can be either added during the channel creation or after the fact
    // with the TryRegister method.
    return _hub.CreateAsync (topic, configuration, worker);
}

Lambdas can also be registered as workers:

Func<MyMessage, CancellationToken, Task> worker = (_, _) => Task.FromResult (true);
return _hub.CreateAsync (topic, configuration, worker);
  1. Publish messages via the hub.
public Task ProduceMessage (string id, string operation, int value) =>
    _hub.Publish (topic, new MyMessage (di, operation, value));
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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 Downloads Last updated
0.3.8 63 6/12/2024
0.3.7 54 6/12/2024
0.2.0 84 5/28/2024
0.0.1 79 5/26/2024