Request: decouple MQTT Client from MQTT Server
nlhnt opened this issue · 5 comments
Hello,
as it stands now, both Client and Server LVClasses inherit from MQTT_Base.lvclass.
Could the Client get decoupled as a seperate library in the future work?
I understand this might now be the goal for this project, but it feels like this is the only mindfully lead project implementing MQTT protocol for labview natively.
Cheers.
Hi @nlhnt ,
thanks for your feedback.
I know it might be a pedantic interpretation, but the client and server are already decoupled. I assume you mean that you would like to install the client without having to install the broker class, and therefore you'd like the installation package to not include both the client and server classes. That is certainly possible!
I think client and server should still both inherit from the MQTT Base no matter what, because a client and a server essentially are symmetrical objects, so all their commonalities can be abstracted, and this is what I've been trying to preserve from the start. These functions include handling of session, connection and the specific MQTT Quality of Service (in the future). In my opinion, it simplifies the unit testing and implementation of new features.
At first, I didn't think I'd offer a client through this library at all, but since I needed one to test the broker, it quickly became obvious (and an easy fruit to pick) that it would be part of the library as well. By doing so, I would have liked to separate the Control Packets from the main library, so that other libraries could be developed on the base packet classes. As part of that refactor, I will gladly get the client and server out of the base library, and have them installed as separate packages that both depend on a MQTT base package.
To be honest, I don't know if I'll do this before version 2.0 because it would break the namespacing for current implementations. As a result, I expect to first implement the Websockets and TLS support before I decouple the package as you suggest. But let me reassure you that I agree that it would be a worthwhile exercise.
This is exactly what I meant.
You are right, there is no need to change the inheritance layout.
Thank you for sharing your insight on the matter and the swift reply!
Well, well, well... I decided to spend the weekend on this and it was a worthwhile effort.
I've been splitting the code into smaller chunks and organized it under a new palette.
The broker project is not purged yet of the other code, but this should be completed soon.
I plan to release the whole hierarchy of packages on the VIPM Community repository.
To find all the pieces, please follow the links below.
You'll find that there is not much less code if you install everything but the server (broker) part, but it is much more malleable now. Especially with respect to the TLS implementation!
Control Packets
https://github.com/LabVIEW-Open-Source/LV-MQTT-Control-Packets
The first package contains the Control Packets, which are the building blocks of MQTT Communication.
(This might be useful for anyone that wants to create their own lightweight MQTT communication and does not want to have the abstraction layers built on top of them.)
There will be a new palette under "Addons":
Connection and MQTT Base abstractions
https://github.com/LabVIEW-Open-Source/MQTT-Connection
The second package is the "Connection and MQTT Base class" which essentially provides the framework for MQTT Client and Servers, but also decouples the connection into an abstract Connection class that can be injected into a client or server implementation, and which allows to build more specific connection schemes, such as a LV2020-based TLS supported Websockets or SSL TCP connection. As explained before in this thread, the core code for this MQTT effort is in LV2013, so I can't add a native LabVIEW SSL connection without first exposing it as an abstract connection. This is the package that allows for this.
Basic Connection Classes
I've created three basic connection classes to show how this is done: TCP, Websockets and a Local Queue.
https://github.com/LabVIEW-Open-Source/MQTT-Connection-LocalQueue
https://github.com/LabVIEW-Open-Source/MQTT-Connection-TCP
https://github.com/LabVIEW-Open-Source/MQTT-Connection-Websockets
These classes are extensions that can be used on their own to create a server and a client architecture. They are called "MQTT Connections" but really, they are just connection classes that can be used without MQTT protocol. I wanted to keep them namespaced because there must be a lot of "Connection" classes how there in the world... and that might cause name conflicts otherwise!
There are examples for each of the connections, but they are essentially all the same with a different configuration:
Change the configuration for the server and clients, and voilà!
It should be a breeze to develop the SSL version of these connections in LV2020, providing a native LabVIEW MQTT client and server.
Client Class and Client session
The client and its specific client session overrides (for the base class' session) are packaged in a separate library.
The MQTT base class handles the shuffling around of the packets, their validation as well as the unique session for each connection. The client class simply provides an override to the client-specific operations. For example, it will reject any packets that should be received only by a server...
Broker Class and Broker session
Finally, this repository will soon contain only the specific code for the server-side implementation of the MQTT protocol. It is very symmetic compared to the client imlementation, so it is quite lightweight. The real difference comes into dealing with multiple clients and therefore multiple sessions. There is a connection handler which provides a process for handling all incoming connections and the stored sessions that are unique features of a server. The server's connection handler deals only with generic connections, so any future extensions for SSL will be completely abstracted away, into the actual connection class.
Client and Broker are now separated:
https://github.com/LabVIEW-Open-Source/MQTT-Client
https://github.com/LabVIEW-Open-Source/LV-MQTT-Broker
BTW, they are being pushed to the VIPM Community repository and will be available later today in VIPM directly.
This is great news, I believe LV community will greatly benefit from your work!
Thanks!