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.
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.
dotnet add package MQTTnet.Extensions.ManagedClient.RoutingRegister 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.
public class TelemetryController : MqttBaseController
{
[MqttRoute("telemetry/temperature")]
public Task OnTemperature(string payload)
{
Console.WriteLine($"Temp: {payload}");
return Ok();
}
}This project is released under the MIT License.
See CONTRIBUTING.md for guidelines on how to open issues, submit pull requests and run the test suite.