njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

it is a bug? #101

Closed skywangxiaoshuai closed 7 years ago

skywangxiaoshuai commented 7 years ago

server return a 500 Timeout::Error (execution expired) when i publish a message use the method client.publish(topic, message, false, 2). but when i use client.publish(topic, message, false, 0) or client.publish(topic, message, false, 1),everything is good. why qos can't use 2?

njh commented 7 years ago

As listed in the limitations in the README, QoS 2 is not currently supported. Although you should have got a better error message.

Given that there is also no persistence or re-connect support in the client, I am not sure that QoS 2 will help you anyway. What were you hoping to achieve by using QoS 2?

skywangxiaoshuai commented 7 years ago

When using QoS 0, the message may not be sent, is not it?

When using QoS 1, the message may be sent repeatedly, is not it?

But what I want is that the message must be sent successfully and will not be sent repeatedly, so which level of QoS should I use?It should be QoS2, right?

Can you help me? thank's!!!

njh commented 7 years ago

Hi,

That is correct. However MQTT must operate over a reliable network protocol (see section 4.2 of the MQTT specification):

The MQTT protocol requires an underlying transport that provides an ordered, lossless, stream of bytes from the Client to Server and Server to Client.

This means that the only time that the different QoS levels come into effect are when the TCP connection disconnects, part way through a Publish. Only then should a message be re-transmitted, after re-establishing the MQTT connection. In normal circumstances this should be a rare occurrence.

Other things to consider:

Quite often, it is easier to use other mechanisms than QoS, because all of your other code has to implement the QoS guarantees too:

It all depends on your application really - but I suspect that using QoS 2 is the least of your worries.

nick.