MVFC.Messaging.Core 3.0.2

dotnet add package MVFC.Messaging.Core --version 3.0.2
                    
NuGet\Install-Package MVFC.Messaging.Core -Version 3.0.2
                    
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="MVFC.Messaging.Core" Version="3.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MVFC.Messaging.Core" Version="3.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MVFC.Messaging.Core" />
                    
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 MVFC.Messaging.Core --version 3.0.2
                    
#r "nuget: MVFC.Messaging.Core, 3.0.2"
                    
#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 MVFC.Messaging.Core@3.0.2
                    
#: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=MVFC.Messaging.Core&version=3.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MVFC.Messaging.Core&version=3.0.2
                    
Install as a Cake Tool

MVFC.Messaging.Core

πŸ‡§πŸ‡· Leia em PortuguΓͺs

CI codecov License Platform NuGet Version NuGet Downloads

The foundation layer for the MVFC.Messaging ecosystem. This package provides the interfaces and abstract base classes that every messaging provider implements. You typically do not use this package directly β€” instead, you install it alongside a provider package (AWS, Azure, RabbitMQ, etc.) that adds the concrete broker integration.

Package

Package Downloads
MVFC.Messaging.Core Downloads

Installation

dotnet add package MVFC.Messaging.Core

Core Interfaces

IMessagePublisher<T>

Defines the contract for publishing messages to a broker. All provider publishers implement this interface.

public interface IMessagePublisher<in T>
{
    /// <summary>
    /// Publishes a single message to the broker.
    /// </summary>
    Task PublishAsync(T message, CancellationToken cancellationToken = default);

    /// <summary>
    /// Publishes multiple messages to the broker in a single operation.
    /// </summary>
    Task PublishBatchAsync(IEnumerable<T> messages, CancellationToken cancellationToken = default);
}

Key points:

  • The generic type T is contravariant (in), so a IMessagePublisher<object> can accept any message type.
  • Both methods support CancellationToken for cooperative cancellation.
  • Batch publishing semantics vary by provider (some use native batch APIs, others publish sequentially).

IMessageConsumer<T>

Defines the contract for consuming messages from a broker. All provider consumers implement this interface.

public interface IMessageConsumer<T>
{
    /// <summary>
    /// Starts consuming messages. Each received message is passed to the handler delegate.
    /// </summary>
    Task StartAsync(Func<T, CancellationToken, Task> messageHandler, CancellationToken cancellationToken = default);

    /// <summary>
    /// Stops consuming messages gracefully.
    /// </summary>
    Task StopAsync(CancellationToken cancellationToken = default);
}

Key points:

  • The messageHandler delegate receives each message along with a CancellationToken.
  • StartAsync is non-blocking β€” it starts a background consumer loop and returns immediately.
  • StopAsync signals the consumer loop to stop and waits for pending work to complete.

Base Classes

MessagePublisherBase<T>

Abstract base class that implements IMessagePublisher<T> with built-in argument validation. Provider publishers inherit from this class and override only the internal methods:

public abstract class MessagePublisherBase<T> : IMessagePublisher<T>
{
    // Override these in your provider:
    protected abstract Task PublishInternalAsync(T message, CancellationToken cancellationToken);
    protected abstract Task PublishBatchInternalAsync(IEnumerable<T> messages, CancellationToken cancellationToken);

    // Public API β€” validates arguments, then delegates to the internal methods:
    public async Task PublishAsync(T message, CancellationToken cancellationToken = default)
    {
        ArgumentNullException.ThrowIfNull(message);
        await PublishInternalAsync(message, cancellationToken).ConfigureAwait(false);
    }

    public async Task PublishBatchAsync(IEnumerable<T> messages, CancellationToken cancellationToken = default)
    {
        ArgumentNullException.ThrowIfNull(messages);
        await PublishBatchInternalAsync(messages, cancellationToken).ConfigureAwait(false);
    }
}

MessageConsumerBase<T>

Abstract base class that implements IMessageConsumer<T> with handler storage and argument validation. Provider consumers inherit from this class:

public abstract class MessageConsumerBase<T> : IMessageConsumer<T>
{
    // The stored handler delegate β€” available to subclasses via the protected property.
    protected Func<T, CancellationToken, Task>? Handler { get; private set; }

    // Override these in your provider:
    protected abstract Task StartInternalAsync(CancellationToken cancellationToken);
    protected abstract Task StopInternalAsync(CancellationToken cancellationToken);

    // Public API β€” stores the handler, then starts the consumer loop:
    public async Task StartAsync(Func<T, CancellationToken, Task> messageHandler, CancellationToken cancellationToken = default)
    {
        ArgumentNullException.ThrowIfNull(messageHandler);
        Handler = messageHandler;
        await StartInternalAsync(cancellationToken).ConfigureAwait(false);
    }

    public async Task StopAsync(CancellationToken cancellationToken = default) =>
        await StopInternalAsync(cancellationToken).ConfigureAwait(false);
}

Creating a Custom Provider

To create your own messaging provider, you need to:

  1. Inherit from MessagePublisherBase<T> and implement PublishInternalAsync and PublishBatchInternalAsync.
  2. Inherit from MessageConsumerBase<T> and implement StartInternalAsync and StopInternalAsync.
  3. Implement IAsyncDisposable on both classes to properly release broker connections.
public sealed class MyBrokerPublisher<T>(MyBrokerClient client, string destination)
    : MessagePublisherBase<T>, IAsyncDisposable
{
    protected override async Task PublishInternalAsync(T message, CancellationToken cancellationToken)
    {
        var json = JsonSerializer.Serialize(message);
        await client.SendAsync(destination, json, cancellationToken);
    }

    protected override async Task PublishBatchInternalAsync(
        IEnumerable<T> messages, CancellationToken cancellationToken)
    {
        foreach (var message in messages)
            await PublishInternalAsync(message, cancellationToken);
    }

    public ValueTask DisposeAsync()
    {
        client?.Dispose();
        return ValueTask.CompletedTask;
    }
}

Compatible Providers

Requirements

  • .NET 9.0+

License

Apache-2.0

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.  net10.0 is compatible.  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.
  • net10.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on MVFC.Messaging.Core:

Package Downloads
MVFC.Messaging.StackExchange

Biblioteca .NET para integração com Redis Streams via StackExchange.Redis, fornecendo abstrações para publicação e consumo de mensagens em streams de forma eficiente e escalável.

MVFC.Messaging.Confluent

Biblioteca .NET para integração com Apache Kafka via Confluent.Kafka, fornecendo abstrações para publicação e consumo de mensagens em tópicos de forma eficiente e escalável.

MVFC.Messaging.InMemory

Biblioteca .NET para mensageria in-memory, ideal para cenários de testes, desenvolvimento e simulação de filas e tópicos sem dependências externas.

MVFC.Messaging.GCP

Biblioteca .NET para integração com Google Cloud Pub/Sub, fornecendo abstrações para publicação e consumo de mensagens em tópicos de forma eficiente e escalável.

MVFC.Messaging.Azure

Biblioteca .NET para integração com Azure Service Bus, fornecendo abstrações para publicação e consumo de mensagens em filas e tópicos de forma simples e eficiente.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.2 203 4/5/2026
3.0.1 202 4/3/2026
2.0.4 202 3/21/2026
2.0.3 192 3/21/2026
2.0.2 196 3/21/2026
2.0.1 195 3/19/2026
1.0.2 304 12/19/2025
1.0.1 320 12/19/2025
1.0.0 318 12/19/2025