How does browser client know publish has failed due to authorisation in MQTT 3.1

Hi,

I have noticed that when I use the HiveMQ browser client and try to publish to a topic which the username and password is not authorised - the browser client immediately disconnects. This is using MQTT 3.1.

But if I try to use NodeJS client I have no way of detecting publish has failed. I am using protocol version 3.1.1. Is there a way to detect publish fail using the NodeJS client ?

If I use protocol version 5 then I can get a call back with with error. But for 3.1 and 3.1.1 this is not working.

Please advice.

Regards,
Harsha

Hello Harsha,

MQTT 3.1 and 3.1.1 versions work the same. Please check here for more details

If a Server implementation does not authorize a PUBLISH to be performed by a Client; it has no way of informing that Client. It MUST either make a positive acknowledgement, according to the normal QoS rules, or close the Network Connection [MQTT-3.3.5-2].

Our suspicion here is that the NodeJS client auto-reconnects immediately, We would like to recommend checking event.log at HiveMQ to check the behaviour.

I hope this helps.

Kind regards,
Sheetal

1 Like

Hi Sheetal,

You are right. The HiveMQ broker is actually disconnecting the client as observed in the event.log - if publish fails due to authorisation issue for all protocol version’s.

Client ID: mqttjs_913cac20, IP: 172.17.0.1 was disconnected. reason: Not authorized to publish on topic…

But the client is reconnecting for all the version’s. But I get a call back with proper error message only for protocol version 5.

Could you please suggest a solution where we can continue to use protocol version 3.1.1 and also detect if publish has failed using the same NodeJS client.

Regards,
Harsha

Hi @Harsha,

Could you please suggest a solution where we can continue to use protocol version 3.1.1 and also detect if publish has failed using the same NodeJS client.

This is the HiveMQ community forum. To increase your chances of finding specific answer to questions about the NodeJS client library you are using, I would suggest reaching out on the appropriate forums or mailing lists.

Cheers,
Florian from the HiveMQ Team.

Thank you @hivemq-support

Regards,
Harsha

1 Like