Replies: 15 comments 13 replies
-
@mdzio any reason why not to use hooks system? Can you describe your usecase little more? |
Beta Was this translation helpful? Give feedback.
-
@mdzio Please let me know if I misunderstand, but I believe your question is that is there any way to subscribe to topics in a way that is similar to the In short, the answer is no. To join in on what @bkupidura said, the simplest way to do this is by utilizing the hooks system and listening to |
Beta Was this translation helpful? Give feedback.
-
My use case is the CCU-Jack. I am the main developer there. The CCU-Jack offers an open communication interface based on MQTT for the HomeMatic smart home system from eQ3. The SurgeMQ MQTT-Server that I continue to maintain is currently embedded there. However, it only supports MQTT version 3.1.1. All data point changes of the system are internally published on this, but also topics are internally subscribed to in order to be able to set data points via MQTT. I could certainly also use the |
Beta Was this translation helpful? Give feedback.
-
For applications, the following API would be very nice: subscription1 := server.Subscribe("a/b/+/c", func(packet packets.Packet) {
// handle packet
})
// function gets called for packages for which the topic filter applies
// ...
subscription2 := server.Subscribe("d/#", func(packet packets.Packet) {
// handle packet
})
// ...
subscription1.Unsubscribe()
// ...
subscription2.Unsubscribe() |
Beta Was this translation helpful? Give feedback.
-
I've experimented with a few ideas for this but it's a little bit more complex than I originally anticipated. However, it's my current active task so there will be a solution - I just haven't found one which 'feels' correct as yet. |
Beta Was this translation helpful? Give feedback.
-
@mochi-co , I had similar need as @mdzio. In addition to filtering the topics of interest, I also needed to extract information from the topics. For example: the topic is in the form of I implemented this based on a modified version go-chi radix tree, so it supports named, regex and wildcard parameters to extract info from the topics. It is used in the OnPublish hook. This is supporting tens of millions concurrent clients, with each node (4 vCPU, ~30% utilization for entire app which embeds mochi-mqtt) supporting ~200K clients (every client sends ~2KB messages every minute). The limit is not due to mochi-mqtt, but some external constraints. If you're interested in re-exploring the hook option, I would be glad to contribute that code. |
Beta Was this translation helpful? Give feedback.
-
@thedevop This sounds very interesting. I think it's going to depend a lot on what people's use cases are - i.e. do you just need to intercept and filter every message, or do you need to pretend to be a client in some degree. I'll await feedback from others as I'm largely impartial. However, it could potentially be a good candidate for a new repo in the organisation if we wanted to make it non-server. As an aside - I haven't got the topics code in front of me currently and it's been a while since I reviewed it, but it does make me wonder if we could collect topic particles for wildcards during the matching process and return them in the |
Beta Was this translation helpful? Give feedback.
-
@mochi-co I do think the idea presented by @thedevop that they have implemented is very interesting; however, I do feel that it may be a more specific use case in which using the hooks makes more sense. I have not looked over the PR yet but I do feel that at least for this first pass a simple implementation should be in favor over a more robust approach. |
Beta Was this translation helpful? Give feedback.
-
Following PR #284: we now have three well defined solutions across a whole range of behaviour and functionality:
Each of these ideas have strong strengths and weaknesses, and I would like to hear your thoughts on it to get a better sense for what would be useful for people. |
Beta Was this translation helpful? Give feedback.
-
As OnPublish hook is not getting deprciated, inline subscription and hook are not mutually exclusive, merely some overlap capabilities. I see the benefit of having a very simple inline client subscription. So with that said, I personally prefer the implementation (#283 or #284) that is:
The following questions may help us determines if we need to suppoort retained message for inline client or not. Do we expect:
|
Beta Was this translation helpful? Give feedback.
-
I've added some thoughts to #284, and cross-linking them here. |
Beta Was this translation helpful? Give feedback.
-
I've added some additional ideas here: #284. and cross-linking them here. I'd like to hear your thoughts on them. |
Beta Was this translation helpful? Give feedback.
-
@mdzio You will find that you can now Subscribe and Unsubscribe, please see v2.4.0 for details 🙂 |
Beta Was this translation helpful? Give feedback.
-
@mochi-co Thank you. I have followed the discussion and think that the implementation will fit. I will try out the new version. |
Beta Was this translation helpful? Give feedback.
-
Great project.
I would like to run the Mochi embedded. For a integration of my application, there is the possibility to publish messages directly via
server.Publish
. Now I would also like to subscribe to topics directly without going via the TCP/IP stack, for example.I have not found an API function for this. Does this exist or is there another possibility?
Beta Was this translation helpful? Give feedback.
All reactions