Moryx.AspNetCore.Mqtt 10.10.1

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

The goal:

The goal is to allow any MORYX developer to create their own Mqtt To MORYX facade, that way you can use Mqtt to communicate with any MORYX facade like: ProductManagement,ResourceManagement etc.

To achieve that, we took inspiration from 3 repositories:

Checking those repositories will give you an idea of what the ManagedMqtt is trying to achieve.

  1. APIs and classes:

    IManagedMqttClient A managed IMqttClient IMqttService : Preferred base class for all services based on Mqtt . IMqttEndpoint : Mqtt Endpoint interface. Every endpoint will implement this interface.

  2. Usage:

    To use the IManagedMqttClient you need to configure it in the Program.cs like so:

    builder.Services.AddMqttClient();
    

    Optionally you can also configure the Mqtt client connection details like so:

    builder.Services.AddMqttClient((provider, options) =>
    {
        options.Connection = new MqttConnectionConfig
        {
            Port = 1883,
            Id = "EndpointDemo1",
            Host = "localhost",
            QoS = MQTTnet.Protocol.MqttQualityOfServiceLevel.ExactlyOnce,
            RootTopic = "mqtt/moryx"
        };
        // optional: add your custom converter/serializer
        options.JsonSerializerOptions.Converters.Add(new MyConverter())
    })
    

    You can also configure the Mqtt client using a configuration file just like any MORYX module. The configuration file can be found inside the default MORYX Config folder. The content is as follows:

    {
      "Id": "my-id",
      "Host": "localhost",
      "Port": 1883,
      "Username": null,
      "Password": null,
      "Tls": false,
      "QoS": "ExactlyOnce", // check the MqttQualityOfServiceLevel enum for more info
      "ReconnectDelayMs": 30000,
      "ReconnectWithClientSession": false,
      "RootTopic":  ""
    }
    
  3. Serialization :

    The serialization of payload is done via MqttMessageSerialization helper class, serialization and deserialization methods requires JsonSerializerOptions that is configured during setup of the Mqtt client.

  4. JsonSerializationOptions :

    // Program.cs
    builder.Services.AddMqttClient(builder: (provider, options) =>
    {
        options.JsonSerializerOptions.Converters.Add(new MyCustomConverter()) // here you add your custom converter
        options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles; // change how references are handled
        //etc..
    })
    //.. other code
    

    If you want to implement your custom service based on the IManagedMqttClient the recommended way is the following:

    • In your Program.cs add the following:
    builder.Services.AddMqttClient(); // this adds the IManagedMqttClient to the service collection
    
    • Create a new C# class and inherit from IMqttService. Note: Dependency injection is supported. Now your service has access to the IManagedMqttClient.

    To add your new service to the service collection do the following:

    builder.Services.AddMqttClient();
                    .AddMqttService<BlablaService>(); // you custom service
    

    Note : the connection to the broker (Connect, re-connect on connection lost etc...) is automatically handled by the IManagedMqttClient.

  5. Endpoints :

    If you need something with topic template and constraint support, you can use the IMqttEndpoint. Here is an example:

    • In your program.cs add the following:
    builder.Services.AddMqttClient() // must be present
                    .AddMqttEndpoints(); // <-- this adds supports for the endpoints
    
    • Create a new C# class that implements the IMqttEndpoint Example.

    There is a minimal version of the Mqtt endpoint, that you can use directly in the Program.cs:

    builder.Services.AddMqttClient()
                    .AddMqttEndpoints(route =>
                    {
                        route.MapGet("my-topic/{id:int}/method/{methodName}", context =>
                        {
                            var messageBuilder = new MqttApplicationMessageBuilder();
                            messageBuilder.WithTopic("another-topic");
                            messageBuilder.WithPayload(MqttMessageSerialization.GetJsonPayload("Hello World!!!!"));
                            return messageBuilder.Build();
                        });
                        // optional : this behave like an eventStream
                        route.MapPost(stream =>
                        {
                            var messageBuilder = new MqttApplicationMessageBuilder();
                            messageBuilder.WithTopic("another-topic");
                            var timer = new Timer(async arg =>
                            {
                                var messageBuilder = new MqttApplicationMessageBuilder();
                                messageBuilder.WithPayload(MqttMessageSerialization.GetJsonPayload("Hello World!!!!"));
                                var message = messageBuilder.Build();
                                await stream.WriteAsync(message);
                            }, null, 0, 10 * 1000);
                        });
                    });
    

    This can be useful for quick prototyping and testing.

  6. Available features in endpoints :

    Endpoints topics support constraint just like in ASP.net controller route.

  7. Route constraint :

    Find the list of available constraints Here

  8. Message Body and Parameters inside a Topic :

    When the endpoint receives a message from the broker, it might come with a Body(payload) and a parameter inside the topic. To access the payload inside your endpoint you can use one of the following methods:

    FromBody<T>(string propertyName)
    
    FromBody(string propertyName, Type type)
    
    //Return the entire body of the request cast to the given type T
    RequestBody<T>()
    
    //Get the request body as an Object
    RequestBodyObject()
    

More resources:

  1. Mqtt Services
  2. Managed Mqtt
Product Compatible and additional computed target framework versions.
.NET 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Moryx.AspNetCore.Mqtt:

Package Downloads
Moryx.AbstractionLayer.Resources.Mqtt.Endpoints

MQTT Endpoints for MORYX Resources

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.10.1 100 8/24/2026
10.10.0 100 8/24/2026
10.9.1 107 8/8/2026
10.9.0 114 7/27/2026
10.8.0 121 7/10/2026
10.7.1 126 6/29/2026
10.7.0 128 6/29/2026
10.6.0 125 6/2/2026
10.5.0 116 5/18/2026
10.4.1 139 4/19/2026
10.4.0 121 4/5/2026
10.3.0 123 3/8/2026
10.2.0 144 2/25/2026