question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
chkr1011commented, Aug 13, 2020

@avishnyak Sure we already mentioned other libs in the readme etc.

2reactions
avishnyakcommented, Aug 12, 2020

I have incorporated all of this feedback in the latest commits and published the beta NuGet package at https://www.nuget.org/packages/MQTTnet.AspNetCore.AttributeRouting.

I have moved the MqttServerApplicationMessageInterceptorDelegate to it’s own singleton called MqttRouter.cs.

Regarding the base controller, I have taken the same approach as AspNetCore. You can either inherit from the MqttBaseController or create your own controller with a MqttController attribute and a property marked with an MqttControllerContext attribute for injection of the incoming message context.

Would you both be ok with me submitting a PR here to add some documentation directing folks who may be interested in this style of programming to the examples and the other repo? I’m thinking some wiki entries and maybe the readme.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attribute-based routing for handling incoming server ...
The idea would be that we create a MqttController and MqttRoute attribute which works in a way that is similar to the AspNet...
Read more >
Routing to controller actions in ASP.NET Core
ASP.NET Core controllers use the Routing middleware to match the URLs of incoming requests and map them to actions. Route templates:.
Read more >
MQTTnet.AspNetCore.AttributeRouting 0.3.16
This addon to MQTTnet provides the ability to define controllers and use attribute-based routing against message topics in a manner that is very ......
Read more >
IoTSharp/MQTTnet.AspNetCore.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...
Read more >
How to use attribute routing in ASP.NET Core
You can set up routing in ASP.NET Core in two different ways: attribute-based routing and convention-based routing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found