MeshWeaver.Messaging.Contract 2.0.3

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

// Install MeshWeaver.Messaging.Contract as a Cake Tool
#tool nuget:?package=MeshWeaver.Messaging.Contract&version=2.0.3                

MeshWeaver.Messaging.Contract

Overview

MeshWeaver.Messaging.Contract defines the core interfaces, types, and abstractions that power the MeshWeaver messaging system. This library provides the contract definitions that enable type-safe message passing between hubs and standardized message handling patterns.

Core Concepts

Addresses

// Unique identifiers for message hubs
public record Address(string Type, string Id);
public record HostAddress() : Address("host", "main");

Message Contracts

Request-Response Pattern
// Base interface for request messages
public interface IRequest<TResponse>
{
    // Marker interface for requests expecting TResponse
}

// Message delivery interface
public interface IMessageDelivery<TMessage>
{
    TMessage Message { get; }
}

Message Hub Interface

public interface IMessageHub
{
    // Send a message and await response
    Task<IMessageDelivery<TResponse>> AwaitResponse<TResponse>(
        IRequest<TResponse> request,
        Action<MessageOptions> configureOptions,
        CancellationToken cancellationToken = default
    );

    // Post a message without waiting for response
    void Post<TMessage>(
        TMessage message,
        Action<MessageOptions> configureOptions
    );
}

Message Options

public class MessageOptions
{
    // Configure message as response to a request
    public void ResponseFor<T>(T request);
    
    // Set target hub address
    public void WithTarget(Address address);
}

Configuration

Hub Configuration

public class MessageHubConfiguration
{
    // Register message types
    public MessageHubConfiguration WithTypes(params Type[] types);
    
    // Register message handler
    public MessageHubConfiguration WithHandler<TRequest>(
        Func<IMessageHub, TRequest, Task> handler
    );
}

Usage Patterns

Defining Messages

// Request message
record PingRequest : IRequest<PongResponse>;

// Response message
record PongResponse;

Message Handler Registration

configuration.WithHandler<PingRequest>((hub, request) =>
{
    // Handle the request
    hub.Post(new PongResponse(), opt => opt.ResponseFor(request));
    return request.Processed();
});

Best Practices

  1. Always define request-response pairs using the IRequest<TResponse> interface
  2. Use strongly-typed messages for type safety
  3. Keep message contracts simple and serializable
  4. Use meaningful addresses for hub identification
  5. Configure message timeouts for reliability
  6. Handle message failures gracefully

Integration

  • Used by MeshWeaver.Messaging.Hub for message processing
  • Provides contract definitions for all MeshWeaver messaging components
  • Enables custom message hub implementations

See Also

Refer to the main MeshWeaver documentation for more information about the overall messaging architecture.

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 (3)

Showing the top 3 NuGet packages that depend on MeshWeaver.Messaging.Contract:

Package Downloads
MeshWeaver.Messaging.Hub

Package Description

MeshWeaver.Data.Contract

Package Description

MeshWeaver.Mesh.Contract

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 570 3/24/2025
2.0.2 540 3/24/2025
2.0.1 201 3/21/2025
2.0.0 233 3/20/2025
2.0.0-preview3 189 2/28/2025
2.0.0-Preview2 225 2/10/2025
2.0.0-preview1 218 1/6/2025
1.0.1 266 10/8/2024
1.0.0 258 10/8/2024