Created
July 25, 2011 18:42
-
-
Save markembling/1104836 to your computer and use it in GitHub Desktop.
A small ruby script which basically spams an MQTT broker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mqtt/client' | |
mqtt = MQTT::Client.new('10.25.2.4') | |
loop do | |
mqtt.connect do |c| | |
c.publish('test/foo/bar','this is a test message #{Time.now}') | |
puts "published a msg" | |
sleep 0.05 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, I still have no clue as to the problem. About the block/connection/disconnection issue though, as I understand it, you are right. The block passed into the connect method is executed after a connection, then it is disconnected. The client (in my case, the
mqtt
variable) can be reused though, as you just have it connect again.If you watch the broker's log output, it does definitely connect, do its thing and disconnect. However I too saw what you're describing when stopping the broker. I assume that is some sort of cleanup process in the broker (removing the record of previous clients perhaps?)
But both my experience and yours seem to point at the gem not being that reliable. Looking at the code myself (I'm no expect, but...) it does look like perhaps things are somewhat optimistic - if it doesn't get what it expects, when it expects it, all hell breaks loose.