-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Topic Router #132
Comments
I support this idea. It would make for cleaner, better readably and maintainable code, at least in my case. I have a code for devices which subscribe to two topics, one for commands and one for measurement values from other sensors. In the callback routine, I currently need to check first the topic and then decide what action to take based on the topic. With the above feature, I can split the code in two callback routines, with clearly dedicated tasks. I'm not very fond of the wildcard idea, though. The library is used primarily in small devices, where the need for wildcarding is rare. But I can see the one or the other use case for this too. |
Thank you all for your comments. I thought about this feature myself a couple of times. However, I think that it unnecessarily complicates the code with little benefit for most users. All my Arduino+MQTT projects involved less than 15 topics, which was easy to handle with a The only thing I see as a possibility would be to implement an additional router class that could be used to handle such cases. To do that properly we first nee to implement a Trie in |
@256dpi what is your strategy when trying to parse which topic it is within your if/elseif/else when the topic has a wildcard like |
You can use |
@256dpi good call, thanks. Just to add to the router idea for anyone picking up this thread, the one |
Currently there is only
onMessage(messageReceived)
callback. It would be nice that user can make routed subscribes that way:client.subscribe("/hello", myHelloHandler);
and that mqtt client lib will automatically route all/hello
messages to thatmyHelloHandler
. To save memory it would be even better if library supports wildcards so user can do:client.subscribe("/hello/%", myHelloHandler);
or
client.subscribe("/hello/%/byebye", myHelloHandler);
and that will cause that it will get routed to
myHelloHandler(int handlerid, String message)
The text was updated successfully, but these errors were encountered: