This gem adds MQTT (Message Queue Telemetry Transport) protocol support to EventMachine, an event-processing library for Ruby.
You may get the latest stable version from rubygems.org:
$ gem install em-mqtt
It depends upon the mqtt gem to perform packet parsing and serialising.
require 'rubygems'
require 'em/mqtt'
# Publish example
EventMachine.run do
c = EventMachine::MQTT::ClientConnection.connect('test.mosquitto.org')
EventMachine::PeriodicTimer.new(1.0) do
puts "-- Publishing time"
c.publish('test', "The time is #{Time.now}")
end
end
# Subscribe example
EventMachine.run do
EventMachine::MQTT::ClientConnection.connect('test.mosquitto.org') do |c|
c.subscribe('test')
c.receive_callback do |message|
p message
end
end
end
- MQTT Homepage: http://www.mqtt.org/
- GitHub Project: http://github.com/njh/ruby-em-mqtt
- Documentation: http://rubydoc.info/gems/em-mqtt/frames
The em-mqtt gem is licensed under the terms of the MIT license. See the file LICENSE for details.
- Author: Nicholas J Humfrey
- Email: njh@aelius.com
- Home Page: http://www.aelius.com/njh/