nats-server icon indicating copy to clipboard operation
nats-server copied to clipboard

Support MQTT QoS=2

Open robinsmidsrod opened this issue 2 years ago • 12 comments

Feature Request

I'm using NATS as an MQTT server together with Home Assistant, and the HASS.Agent Windows companion application. The HASS.Agent application uses QoS=2 when it wants to enable commands to run on the Windows machine from Home Assistant. When this is enabled, the MQTT connection is disconnected and a message about QoS=2 not supported is logged.

Proposed Change:

Support MQTT QoS=2.

Who Benefits From The Change(s)?

People using Home Assistant and HASS.Agent with NATS MQTT service.

Alternative Approaches

None at the moment, because HASS.Agent doesn't support setting QoS level.

robinsmidsrod avatar Jul 06 '22 11:07 robinsmidsrod

Thank you for your interest. Unfortunately, there is no plan to implement QoS2 in NATS Server at this stage.

kozlovic avatar Jul 06 '22 15:07 kozlovic

@kozlovic You shouldn't by any chance have a link to a document that describes why you have no current plans of supporting it? I'm going to assume it's quite tricky with how MQTT is implemented in NATS, but it could also be as trivial that you don't have time to prioritize it.

robinsmidsrod avatar Jul 07 '22 12:07 robinsmidsrod

@robinsmidsrod There is no document per-se. I have written the MQTT code in the NATS Server and I am concerned with the added complexity of QoS2 and that we don't have much time with all other priorities. I will, however, re-open this issue and leave it as enhancement request in case the community wants to contribute with a nice PR ;-)

kozlovic avatar Jul 07 '22 15:07 kozlovic

I think there could be many of us wanting to use NATS for its features and also as a full MQTT broker. What kind of help would be needed for this effort?

@kozlovic still haven't dig into the NATS code but do you consider it would be doable to support the full MQTT spec?

pablitovicente avatar Jul 17 '22 16:07 pablitovicente

It seem that robinsmidsrod does not need QoS2. Problem is if message arrive with qos2 connection is closed. Would it be possible add configuration option downGradeQos2ToQos1 that will allow treat QoS2 messages like qos1 messages?

tvojacek avatar Jul 27 '22 07:07 tvojacek

@TomasVojacek Your observation is correct. I just need the MQTT broker (NATS) to stay connected, even if it doesn't support QoS=2. If there is a "force downgrade" option in the protocol that HASS.Agent will be able to tolerate and continue working with then that is a workaround for me. But if HASS.Agent ignores that and expects QoS=2 behavior then we're no further in terms of solving my integration compatibility issue. I think QoS=2 support in NATS would be awesome, though.

robinsmidsrod avatar Jul 27 '22 11:07 robinsmidsrod

I will look into more, I don't think a simple downgrade will work, IIRC QoS2 has a 4-way handshake that we would need to support in some form or fashion even if we "downgrade" internally to QoS1.

Can the HASS agent be configured not to use QoS2?

derekcollison avatar Jul 27 '22 16:07 derekcollison

@derekcollison I've posted a request in their bug tracker to set max used QoS-level, but it is (to my knowledge) not yet implemented. Here is the link to their bug tracker: https://lab02research.youtrack.cloud/issue/hassagent-118

robinsmidsrod avatar Jul 28 '22 20:07 robinsmidsrod

ok thanks, will see what we can do on our side, but a bunch of other things taking precedent at the moment.

derekcollison avatar Jul 29 '22 00:07 derekcollison

Now that we have 2.9 released, I want to follow up on this.

I would like NATS to be able to interop with HomeAssistant. I do think that QoS2 is probably being misused a bit in this application. Not sure if there has been any movement on this from a hassagent perspective.

derekcollison avatar Sep 10 '22 17:09 derekcollison

@derekcollison As far as I can tell, there's been no activity on the HASS.Agent side of things with regards to this issue.

robinsmidsrod avatar Sep 10 '22 19:09 robinsmidsrod

ok, I thought the same when I looked.

We will get this implemented, like I said, would like NATS to be able to work with HomeAssistant for sure.

derekcollison avatar Sep 10 '22 21:09 derekcollison

please assign me

ariel-zilber avatar Oct 12 '22 11:10 ariel-zilber

@ariel-zilber I have assigned this to you as requested. Thank you for offering to help!

kozlovic avatar Oct 13 '22 22:10 kozlovic

Great !! I am working on it

ariel-zilber avatar Oct 19 '22 15:10 ariel-zilber

Any progress on this issue?

leandrofars avatar Apr 27 '23 18:04 leandrofars

None at this point from Synadia side, we do plan on doing some improvements to MQTT layer in 2.10.

derekcollison avatar Apr 27 '23 21:04 derekcollison

@robinsmidsrod I am curious if you were able to try out 2.10.x and had time to report back if Home Assistant works with nats now? I was planning on giving it a shot but it looks like there are still limitations. Thanks!

onedr0p avatar Oct 27 '23 19:10 onedr0p

@onedr0p No, I have had no time to try this out. Honestly, after I figured out how to support both TLS and non-TLS (for my ESP8266 devices) in Mosquitto this hasn't had the same priority for me. I will probably revisit it sometime in the future, but you should try yourself and report back if it indeed works and what the current limitations are.

robinsmidsrod avatar Nov 02 '23 09:11 robinsmidsrod

I'd like to add a CI test for compliance with Home Assistant. Can you please provide a few details on what software version, etc I should try it with? There appear to be multiple products on the homepage. CC @robinsmidsrod @onedr0p

levb avatar Nov 02 '23 14:11 levb

@levb they have container images here, the most recent version is 2023.11.0

onedr0p avatar Nov 02 '23 15:11 onedr0p