-
Notifications
You must be signed in to change notification settings - Fork 16
subscribe / on_subscribe #14
Comments
oh, and I'm using |
oh, and the
This after running the exemple above a couple of times, o leaving it to reconnect :) Also, I'm running Again, maybe I'm being an idiot somewhere and this is not so much a lib problem, but either way, just wanted to bounce some ideas off you :) thanks |
Thanks for all the great context @dramalho - will take a look shortly ... |
awesome, thanks :) |
It seems like I'm getting the same behaviour from require 'mosquitto'
mqtt_host = 'localhost'
mqtt_port = 1883
client_id = Process.pid.to_s
mqtt = Mosquitto::Client.new # default options
mqtt.on_connect do |_|
puts 'Mqtt on_connect'
%w(msg1 msg2 msg3).each_with_index do |msg, idx|
puts "Publishing #{msg} to topic test with mid #{idx+100}"
mqtt.publish(idx + 100, msg, 'test', Mosquitto::AT_MOST_ONCE, false)
end
end
mqtt.on_publish do |mid|
puts "Published message with mid #{mid}"
end
mqtt.loop_start
mqtt.connect_async(mqtt_host, mqtt_port, 10) outputs Mqtt on_connect
Publishing msg1 to topic test with mid 100
Publishing msg2 to topic test with mid 101
Publishing msg3 to topic test with mid 102
Published message with mid 3
Published message with mid 2
Published message with mid 1 |
mosquitto is generating the message id-s message_id = mqtt.publish(msg, 'test', Mosquitto::AT_MOST_ONCE, false) this message_id will be the same as in the on_publish callback additionally you should see
i do not know why it is in a reversed order |
Hi
quick check, maybe I'm being an idiot here :)
I'm using them gem to connect to a mosquitto instance running locally . I'm building a bunch of agent that will be running for a while so I'm trying to be somewhat resilient here and because everything runs asynchronously, so I have, for instance, a callback on
on_connect
to flush any topic subscriptions that other parts of the agent might have requested before mosquitto was actually connected.For that, and following the documentation, I'm assigning each topic a numerical id that I provide when subscribing to the topic, I then have a callback block on
on_subscribe
that I would use to mark a certain topic assubscribed
(and if for some reasonflush_topics
would need to run again, I would skip those)Anyway, my issue is I'm assigning topic subscription an id, but the callback responds with a completely different number, so I can't match both .
Some code might help here :) , this is a simplification of what I'm doing, but it's fine
and this outputs the following
Now, my expectation from the documentation on subscribe and on_subscribe would be that the
mid
was there to achieve this sort of async matching, but the behaviour seems to indicate that thesubscribe
method is ignoring the givenmid
and applying a sequencial mid that theon_subscribe
then reports (or something) :)The text was updated successfully, but these errors were encountered: