Skip to content

Attribute-based routing for handling incoming server messages (similar to AspnetCore)

Created by: avishnyak

Describe the feature request

Since the server has the capability to listen to messages directly as they come in, I think it would be a good idea to borrow the concept of attribute-based routing from the AspnetCore framework. The idea would be that we create a MqttController and MqttRoute attribute which works in a way that is similar to the AspNet framework. The matching would be done against the path of the Mqtt messages and the appropriate action would be invoked by the MqttServer.

Which project is your feature request related to?

  • MQTTnet.AspnetCore

Describe the solution you'd like

  • Create a base MqttController
  • Create MqttController attribute
  • Create MqttRoute attribute
  • Add MapMqttControllers configuration as a chainable config to UseMqtt Endpoint config in MQTTnet.AspnetCore.
  • If there are any configured controllers, match them against a routing table and invoke the appropriate Action

Describe alternatives you've considered

Alternatives are:

  • Do nothing (everyone implements whatever they want in user space)
  • Issue guidance in the form of a separate GitHub project and have everyone re-implement as needed on their own project
  • Plug into the AspNet endpoint routing directly (not a 100% fit of the paradigm)

Additional context

If this feature is part of the AspNet integration package and optional (needs to use .MapMqttControllers to opt into this behavior, I believe it will be fully backwards compatible and offer a nicer onboarding for new users who are used to the AspNet routing paradigm.

I would be happy to do the implementation if this is something the project would like to add.