Skip to content

Easily create Controllers and Actions to process incoming MQTT messages using a familiar paradigm and MQTTnet

License

Notifications You must be signed in to change notification settings

lucaschoeneberg/MQTTnet.Extensions.ManagedClient.Routing

 
 

Repository files navigation

NuGet Badge License: MIT

MQTTnet Extensions ManagedClient Routing

MQTTnet Extension ManagedClient Routing is a fork of https://github.com/IoTSharp/MQTTnet.Extensions.ManagedClient.Routing

This addon to MQTTnet provides the ability to define controllers and use attribute-based routing against message topics in a manner that is very similar to AspNet Core.

Overview

MQTTnet.Extensions.ManagedClient.Routing extends MQTTnet's ManagedMqttClient with controller based routing. Use it when you want to organize MQTT handlers using MVC style controllers and attribute routes.

Installation

dotnet add package MQTTnet.Extensions.ManagedClient.Routing

Usage

Register your MQTT controllers in the DI container and enable routing:

builder.Services.AddMqttControllers();

app.UseAttributeRouting(); // or managedClient.WithAttributeRouting(app.Services);

To execute code before and after each controller action you can register an IRouteInvocationInterceptor. Implement the interface and hook it up when adding the controllers:

builder.Services.AddMqttControllers(opt =>
    opt.WithRouteInvocationInterceptor<MyInterceptor>());

RouteExecuting is called before the handler runs and RouteExecuted afterwards. See the architecture overview for details.

Example controller

public class TelemetryController : MqttBaseController
{
    [MqttRoute("telemetry/temperature")]
    public Task OnTemperature(string payload)
    {
        Console.WriteLine($"Temp: {payload}");
        return Ok();
    }
}

MIT License

This project is released under the MIT License.

Contributing

See CONTRIBUTING.md for guidelines on how to open issues, submit pull requests and run the test suite.

About

Easily create Controllers and Actions to process incoming MQTT messages using a familiar paradigm and MQTTnet

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%