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
538 stars 135 forks source link

unable to establish QoS1 sessions #141

Open dmitrym0 opened 2 years ago

dmitrym0 commented 2 years ago

Hey folks,

I'm trying to establish a non clean session on my "subscriber", but it doesn't seem to work. I've verified that QoS1 is on the publisher by using mosquito_sub tools. This is how I spin up my consumer:

#!ruby
require 'rubygems'
require 'mqtt'

# Subscribe example
c = MQTT::Client.connect(
  :host => 'localhost',
  :port => 1883,
  :ssl => false,
  :username => 'user',
  :password => 'password',
  :clean_session => false,
  :client_id => "consumer",
)
  puts c.clean_session
  puts c.client_id

  c.get('test') do |topic,message|
    puts "Recv: #{topic}: #{message}"
  end

If I use the above script to connect, then disconnect, the messages generated in the interim are lost.

If I use

mosquitto_sub -i subscriber -t test -h localhost -v -d -c -q 1

then I get queued up messages delivered.

I also tried this with paho.mqqt.ruby, and that works fine as well.