LSFlow 1.0.3

dotnet add package LSFlow --version 1.0.3
                    
NuGet\Install-Package LSFlow -Version 1.0.3
                    
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="LSFlow" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LSFlow" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="LSFlow" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LSFlow --version 1.0.3
                    
#r "nuget: LSFlow, 1.0.3"
                    
#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.
#:package LSFlow@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LSFlow&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=LSFlow&version=1.0.3
                    
Install as a Cake Tool

LSFlow.Messaging

LSFlow.Messaging is a robust and complete messaging library for .NET, focusing on simplicity and reliability. It's designed to handle asynchronous communication between services, ensuring message delivery through the Outbox pattern and simplifying the configuration of topologies and event consumption.


Installation and Setup

To use the library, add the appropriate NuGet packages to your project:

# Main package for RabbitMQ
dotnet add package LSFlow.Messaging.Rabbit

# Package for the Outbox pattern
dotnet add package LSFlow.Outbox

# Or just
dotnet add package LSFlow

# Package for Entity Framework Core with Npgsql (or another provider)
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL

Client and Topology Configuration (Publisher)

Configuring the RabbitMQ client and topology is done directly in the Program.cs file. You need to set environment variables and use the extension methods to configure the services.

// 1. Set environment variables
// They must be accessible to the application (e.g., .env, Dockerfile)
Environment.SetEnvironmentVariable("RABBIT_USERNAME", "rabbitmq");
Environment.SetEnvironmentVariable("RABBIT_PASSWORD", "rabbitmq");
Environment.SetEnvironmentVariable("RABBIT_HOSTNAME", "localhost");
Environment.SetEnvironmentVariable("RABBIT_PORT", "5672");
Environment.SetEnvironmentVariable("RABBIT_VHOST", "/");

// 2. Add RabbitMQ services
builder.Services.AddRabbitClient();

// 3. Create and configure the topology (exchanges, queues)
var scope = app.Services.CreateScope();
var topology = scope.ServiceProvider.GetService<Topology>() ?? throw new NullReferenceException("Error occurred during topology creation.");
await topology.AddExchange("payments", ExchangeType.Topic);
await topology.AddQueue("payments.events");
await topology.AddQueue("payments.notifications");

Outbox and DbContext Configuration

The Outbox pattern ensures that messages are saved to the database and published to the queue atomically. For this, your application's DbContext must implement the IOutboxDbContext interface.

// In your DbContext (e.g., AppDbContext.cs)
public class AppDbContext : DbContext, IOutboxDbContext
{
    // Add DbSets for the Outbox
    public DbSet<OutboxMessage> OutboxMessages { get; set; }
    public DbSet<ProcessedMessage> ProcessedMessages { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Use the extension method to configure the Outbox
        modelBuilder.AddOutbox();
    }

    // Configure your database (e.g., PostgreSQL)
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql($"Host=localhost;Port=5433;Username=postgres;Password=postgres;Database=postgres");
    }
}

To register the Outbox and DbContext in Program.cs, use the following extension methods:

builder.Services.AddDbContext<IOutboxDbContext, AppDbContext>();
builder.Services.AddOutbox();

RabbitConsumer Configuration (Consumer)

To consume messages, you need to configure the RabbitConsumer and the bindings that define which queues your application will listen to.

// 1. Define bindings for the queues the application will consume
var bindings = new List<QueueBinding>
{
    new() { ExchangeName = "orders", QueueName = "orders.events" }
};

// 2. Add the RabbitConsumer
builder.Services.AddRabbitConsumer(bindings);

Creating and Configuring the EventDispatcher

The EventDispatcher is responsible for publishing messages. It's a concrete class that implements the IEventDispatcher interface and must be injected in Program.cs.

// In Program.cs, register the service
builder.Services.AddScoped<IEventDispatcher, EventDispatcher>();

Creating and Configuring Event Handlers

To process incoming messages, create concrete classes that implement IEventHandler<T>, where T is the message (event) type. Then, register them in Program.cs.

// Example of an Event Handler
public class OrderCreatedHandler : IEventHandler<OrderCreated>
{
    public Task Handle(OrderCreated message, CancellationToken cancellationToken)
    {
        Console.WriteLine($"Received OrderCreated event: {message.OrderId}");
        // Your business logic goes here...
        return Task.CompletedTask;
    }
}

// In Program.cs, register the handler
builder.Services.AddScoped<IEventHandler<OrderCreated>, OrderCreatedHandler>();

Upcoming Features

  • Kafka Integration: We plan to add a client for Kafka, offering an alternative to RabbitMQ.
  • Redis for Event Caching: Functionality to use Redis as a cache for events will be implemented, optimizing the processing of duplicate messages.
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.3 334 9/17/2025
1.0.2 324 9/16/2025
1.0.1 328 9/16/2025
1.0.0 330 9/16/2025