MQTT.js vNext Architecture Feedback #1324
-
Hey all, @YoDaMa here. I'm creating this discussion and migrating some of my writing from the existing vNext PR that I created to the Github Discussions since this seems like a much more apt medium for community engagement. As part of the ongoing effort to revive / rearchitect this project, I've been working on creating an easily digestible UML-ish diagram of the existing architecture, as well as a new architecture. The goal is these will make it easier for community members with not so much experience in the repository or time to dive deep into all the code to contribute. Architecture can sometimes be hard to see when you're reading through the codebase and looking at all the weird red-herrings of the existing design. Here is a class diagram of the existing MQTT.js Library's code, from the perspective of a User Application: The existing library's code is structured around what I'll call a Connection Factory. If you look in lib/connect/index.js you will see the main entry point of the client generation is through this file, where connection is chosen based on the protocol of the parsed URL given during the call to connect ( We can model the connection factory like so: I've left out a few of the existing "ConnectionStream implementations" as I'll call them. You can see in the existing repo that there are:
Of all of these, two are Alibaba specific implementations, to my knowledge: wx.js and ali.js. I am confused as to why a company specific set of factories has been added to this repository, and don't see a compelling reason to keep them unless there's some proxy support that is useful for all users of the MQTT.js library, regardless of service they're connecting to. (I work for Microsoft, but it doesn't make sense to build Microsoft specific connection layers into this library either.) With all that being covered, it's now a community dialogue about where we go. How do people like the existing API? Any changes people would like to see? And how this library can be written in a way so it is more testable, and ultimately more maintainable by those without historical 'tribal' knowledge of how different pieces of it's functionality came to be? I have anticipated that I will be the main code writer on this rewrite project, which is fine. But I don't want to make drastic changes that everyone doesn't know about or dislikes. So your feedback and engagement is crucial. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 7 replies
-
This is only scratching the surface, but I have a few ideas here:
|
Beta Was this translation helpful? Give feedback.
-
And, for what it's worth, I've been neck-deep in rhea and there might be something to be learned from looking at their architecture. I don't think mqttjs needs something quite as complex, but the way they break up transport, terminus, session, container, connection, endpoint, and frames is interesting. |
Beta Was this translation helpful? Give feedback.
-
There have been some discussions around the use of The interface ConnectionFactory {
getConnectionStream: function (options: ConnectOptions): Duplex
} and this would then be passed into via options like: const options = {
brokerUrl: 'myurl.com'
...
customConnectionFactory: {
getConnectionStream(options: ConnectOptions): Duplex {
...
return myCustomStream
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I'm a heavy user of mqtt.js, and there's a lot of attention on the next step in the design of mqtt.js. For the previous mqtt.js its data flow pattern is really complicated, and I think refactoring is really necessary.
|
Beta Was this translation helpful? Give feedback.
-
Could we improve parallel messages on the next version |
Beta Was this translation helpful? Give feedback.
-
This is less about how the library is structured, but more about its Interface. Perspective of a light user.
|
Beta Was this translation helpful? Give feedback.
-
In my view the current version is way to heavy on dependencies. ESM would also help in treeshaking. My 2cts ;-) |
Beta Was this translation helpful? Give feedback.
-
We are moving our development work for the next generation of MQTT.js to a separate repo. I'll close this discussion to avoid confusion and keep everything in that repo. If you have any thoughts or feedback on vNext, please open an issue in that repo. |
Beta Was this translation helpful? Give feedback.
We are moving our development work for the next generation of MQTT.js to a separate repo. I'll close this discussion to avoid confusion and keep everything in that repo. If you have any thoughts or feedback on vNext, please open an issue in that repo.