I am new to mqtt and would like to get my head around something.
I need to get messages from (subscribe to) topics from a remote mosquitto
broker. The documentation for the service says I need to run a mosquitto
broker on my server.
If I understand correctly then a script that uses the mqtt
gem and manages to connect using something like this:
MQTT::Client.connect(conn_opts) do |c|
# The block will be called when you messages arrive to the topic
c.get('test') do |topic, message|
puts "#{topic}: #{message}"
end
end
IS a broker? Do I need to run mosquitto on my machine or can I get away with just a script and mqtt
?
The doc describes the architecture and includes these lines:
The 3rd party platform needs an MQTT broker installed that will allow communication with the different boxes on our servers. The broker on our servers will initiate the connection and provide the credentials to allow bidirectional communication.
The architecture I have in mind is a scheduled background process, using ruby-mqtt
, that will spawn, connect with the remote mosquitto
server and pull down new messages in batches before finishing. Does this sound like a reasonable approach for getting messages from a remote mosquitto
broker?
I have a sneaky suspicion there is something I am not getting... any help/direction will be appreciated. Thanks!