VL.Messaging.Abstraction 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package VL.Messaging.Abstraction --version 1.1.1
NuGet\Install-Package VL.Messaging.Abstraction -Version 1.1.1
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="VL.Messaging.Abstraction" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VL.Messaging.Abstraction --version 1.1.1
#r "nuget: VL.Messaging.Abstraction, 1.1.1"
#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 VL.Messaging.Abstraction as a Cake Addin
#addin nuget:?package=VL.Messaging.Abstraction&version=1.1.1

// Install VL.Messaging.Abstraction as a Cake Tool
#tool nuget:?package=VL.Messaging.Abstraction&version=1.1.1

Abstraction Messaging

This package contains the abstraction for potenital message brokers.

Getting Started

  1. Install package VL.Messaging.Abstraction

    dotnet add package VL.Messaging.Abstraction
    
  2. Interfaces

    public interface IMessageConsumer
    {
        public Task ConsumeAsync(CancellationToken cancellationToken = default);
    }
    
    public interface IMessageHandler<in TMessage> : IMessageHandler where TMessage : Message, new()
    {
        public Task HandleAsync(TMessage message, CancellationToken cancellationToken = default);
    }
    
    public interface IMessageHandlerDescriptor
    {
        public Type MessageType { get; }
    
        public IMessageHandler GetMessageHandler();
    }
    
    public interface IMessagePublisher<in TMessage> where TMessage : Message, new()
    {
        public Task PublishAsync(TMessage message);
    }
    
  3. Classes

public abstract class Message
{
    protected Message() : this(Guid.NewGuid(), DateTimeOffset.UtcNow) { }

    protected Message(Guid id, DateTimeOffset creationDate)
    {
        Id = id;
        CreationDate = creationDate;
    }

    public Guid Id { get; }

    public DateTimeOffset CreationDate { get; }

    public string Source { get; set; } = "DefaultSource";
};

public abstract class MessageHandlerBase<TMessage> : IMessageHandler<TMessage> where TMessage : Message, new()
{
    public abstract Task HandleAsync(TMessage message, CancellationToken cancellationToken = default);

    public Task HandleAsync(Message message, CancellationToken cancellationToken = default)
    {
        if (message is null)
        {
            throw new ArgumentNullException(nameof(message));
        }

        if (message is TMessage specificMessage)
        {
            return HandleAsync(specificMessage, cancellationToken);
        }

        throw new InvalidOperationException("Invalid message type." +
            $"Expected type \"{typeof(TMessage).Name}\" instead of \"{message.GetType().Name}\".");
  }
}

public class MessageHandlerDescriptor<TMessage> : IMessageHandlerDescriptor where TMessage : Message, new()
{
    private readonly Func<IMessageHandler> _factory;
  
    public MessageHandlerDescriptor(Func<IMessageHandler<TMessage>> factory)
    {
        MessageType = typeof(TMessage);
        _factory = factory ?? throw new ArgumentNullException(nameof(factory));
    }
  
    public Type MessageType { get; }

    public IMessageHandler GetMessageHandler()
    {
        return _factory();
    }
}
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 (1)

Showing the top 1 NuGet packages that depend on VL.Messaging.Abstraction:

Package Downloads
VL.Messaging.RabbitMQ

A thin wrapper around RabbitMQ that simplifies and standardizes consuming/publishing messages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.5 106 12/22/2023
1.1.4 102 12/22/2023
1.1.3 95 12/22/2023
1.1.2 96 12/22/2023
1.1.1 75 12/22/2023
1.1.0 76 12/22/2023
1.0.0 127 12/18/2023