Infinity.Toolkit.Messaging 1.0.0

dotnet add package Infinity.Toolkit.Messaging --version 1.0.0                
NuGet\Install-Package Infinity.Toolkit.Messaging -Version 1.0.0                
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="Infinity.Toolkit.Messaging" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Infinity.Toolkit.Messaging --version 1.0.0                
#r "nuget: Infinity.Toolkit.Messaging, 1.0.0"                
#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 Infinity.Toolkit.Messaging as a Cake Addin
#addin nuget:?package=Infinity.Toolkit.Messaging&version=1.0.0

// Install Infinity.Toolkit.Messaging as a Cake Tool
#tool nuget:?package=Infinity.Toolkit.Messaging&version=1.0.0                

Infinity.Toolkit.Messaging

Infinity Toolkit Messaging is a no frills messaging lightweight library with a super simple API. It can be used to send messages between different parts of the application. The library is built with simplicity in mind and is designed to be easy to use and easy to understand. The nomenclature is following Async API and the library is built with the idea of being able to easily integrate with any messaging system such as Azure Service Bus, RabbitMQ, Kafka etc.

Features

  • An Async API inspired API.
  • An In-Memory message bus
  • Azure Service Bus integration

Quick Start

To get started with Infinity.Toolkit.Messaging follow these steps:

  1. Look at the sample project in the repository. The sample project found here MessagingSample is a simple web api that demonstrates how to use the library.
  2. Create a new project and integrate the library.

Let's look create a new project and integrate the library.

  1. Create a new web api project using the dotnet cli.
dotnet new webapi -n MyWebApi
  1. Add the Infinity.Toolkit.Messaging package to the project.
dotnet add package Infinity.Toolkit.Messaging
  1. Start by creating a message class that will be sent between different parts of the application. For this sample let's reuse the WeatherForecast class from the sample project.
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
  1. Create a message handler that will handle the message. The message handler should implement the IMessageHandler<TMessage> interface.
internal class WeatherForecastHandler : IMessageHandler<WeatherForecast>
{
    public Task HandleAsync(WeatherForecast message, CancellationToken cancellationToken)
    {
        Console.WriteLine($"Received message: {message.Summary}");
        return Task.CompletedTask;
    }
}
  1. Now it's time to add and configure the message bus. First add the message bus to the services collection in the Program.cs file.
using Infinity.Toolkit.Messaging;

var builder = WebApplication.CreateBuilder(args);
builder.AddInfinityMessaging();

var app = builder.Build();
...
  1. Good, now the message bus is added to the services collection. Next, we need to configure a broker that will be used to send and receive messages. In this sample, we will use the in-memory message broker.
builder.AddInfinityMessaging().ConfigureInMemoryBus();
  1. Build and run the application and make sure everything is working as expected.

  2. Now we need to configure a ChannelProducer that will be used to send messages. In this sample, we will use the in-memory channel producer.

builder.AddInfinityMessaging()
    .ConfigureInMemoryBus(builder =>
    {
        builder.AddChannelProducer<WeatherForecast>(options => { options.ChannelName = "weatherforecasts"; })
    });

This will add a channel producer that will send messages of type WeatherForecast to the channel named weatherforecasts.

  1. Now we can send messages to the channel but we also need to configure a channel consumer that will consume the messages. In this sample, we will use the in-memory channel consumer that consumes messages from the weatherforecasts channel. The channel is configured as a topic so we need to configure a subscription name as well.
builder.AddInfinityMessaging()
    .ConfigureInMemoryBus(builder =>
    {
        builder
            .AddChannelProducer<WeatherForecast>(options => { options.ChannelName = "weatherforecasts"; })
            .AddChannelConsumer<WeatherForecast>(options =>
            {
                options.ChannelName = "weatherforecasts";
                options.SubscriptionName = "weathersubscription";
            });
    });
  1. Now we can send messages to the channel and consume the messages. However we have no handler that will handle the messages with the type WeatherForecast. Let's add the handler to the services collection.
builder.AddInfinityMessaging()
    .ConfigureInMemoryBus(builder =>
    {
        builder
            .AddChannelProducer<WeatherForecast>(options => { options.ChannelName = "weatherforecasts"; })
            .AddChannelConsumer<WeatherForecast>(options =>
            {
                options.ChannelName = "weatherforecasts";
                options.SubscriptionName = "weathersubscription";
            });
    })
    .MapMessageHandler<WeatherForecast, WeatherForecastMessageHandler>();
  1. Let's add an endpoint so we can send messages to the channel.
app.MapPost("/send", async (ChannelProducer<WeatherForecast> producer) =>
{
    await producer.SendAsync(new WeatherForecast(DateTime.Now, 20, "Sunny"));
    return Results.Ok();
});
  1. Now we have a complete setup with a message bus, channel producer, channel consumer and a message handler. We can now send messages to the channel and the message handler will handle the messages.

Contributing

If you have any ideas, suggestions or issues, please create an issue or a pull request. Or reach out to me on BlueSky.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Infinity.Toolkit.Messaging:

Package Downloads
Infinity.Toolkit.Messaging.AzureServiceBus

Azure Service Bus Integration for Infinity.Toolkit.Messaging.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 82 1/30/2025