Closed FranciscoGJ closed 4 years ago
Just create two different clients.
client1 = MQTT::Client.connect('test.mosquitto.org')
client2 = MQTT::Client.connect('iot.eclipse.org')
Yes, I tried. But I can not get the two clients to listen. What would the code be like? Or is it necessary that each instance be found in different threads?
Can you provide an example of what you are trying to do?
Are you subscribing in both clients?
This is an example:
client1 = MQTT::Client.connect('test.mosquitto.org')
client2 = MQTT::Client.connect('iot.eclipse.org')
client1.get('backend/device/1') do |topic,message|
@manage.check(topic,message)
end
client2.get('backend/ttn') do |topic,message|
@manage.check(topic,message)
end
It looks like you are blocked by the first client.get
That is right. The ruby MQTT::Client
is synchronous.
The #get
blocks waiting for a message and calls the block for each message received.
If you want to wait for messages from two different brokers in the same process, then using threads might be an option.
I need to connect to two different brokers. How can I do it?