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 support for MQTT version 3.x #5158
base: master
Are you sure you want to change the base?
Conversation
New Config key EVENT_FORWARD_MQTT_VERSION added. By default version 5 is used as this has been used before. Version 3 is support. The EventForwarderMqtt checks the version setting and creates an MqttClientV3 or V5.
Introduce MqttClientFactory for testability. Added unit-tests for EventForwarderMqtt and MqttClientFactory.
I don't like this duplication. Are they not backward or forward compatible? |
Me too. But I didn't see a more elegant solution if you want to Stick to hivemq. Maybe I just overlooked it. I wish hivemq would detect the version supported by the server or at least offer a version setting in the client builder. I tried to minimize the Code redundancy by separating the EventForwarderMqtt from the client creation. Maybe there is another mqtt library for java if this ist not acceptable. |
Is 3 forward compatible with 5? Can MQTT 3 client send data to MQTT 5 server? |
Not an expert for MQTT. I stumbled over this: "Most likely important: MQTT v5.0 is not backward compatible (like v3.1.1). Obviously too many new things are introduced so existing implementations have to be revisited." ChatGPT says a MQTT 3.1 client is able to connect to a MQTT 5 server. You'll only lose the latest features. Not Sure If this ist true. That would mean we could simply switch to the MQTT3 client. Unfortunately I don't have a v5 Server around and have no experience setting one up. |
Maybe ClientV5 -> Server v3.1 doesn't work but the opposite direction does? |
That's what I'm wondering. |
I have used v3 clients fine with v5 servers in other applications. I have used paho in many applications connecting to v3 and v5. Hivemq have different classes for interacting with v5 and v3 servers. mqtt 5 have some new features, but as I have seen in current traccar code when I made a refactor to create a position forwarded traccar only use basic things. I will change my code to use the mqtt3 client to test with my v5 server, and if it works fine in next days will push a new commit for the #5202 |
Its better to only support MQTT3 as there as no really useful additions like headers. As long as the MQTT broker accepts v3 messages its ok. All brokers will happily send to v3 and v5 subscribers. |
I had issues connecting with traccar to my aedes broker that currently only supports MQTT 3.x. It doesn't support MQTT5 yet.
It seems like the hivemq client library's Mqtt5AsyncClient doesn't fallback to MQTT 3.x when the server doesn't support version 5 features. The hivemq dev have a completely separate package structure (redudant) for v3 and v5. The classes don't have common interfaces.
I've added a setting to tell traccar which version to use. If the setting is not there or different from v3 version 5 like before will be used by default.
Discussion was here: https://www.traccar.org/forums/topic/release-56-mqtt-support-for-event-forwarding/page/3/
In my setup I could finally connect to my MQTT broker with these changes.