-2

I have set up mosquitto with NodeJs and EMQX with the NodeJs in 2 different applications. I want to create a bridge between both my MQTT clients and send and receive values from both ends.

Tried creating a bridge using WebSocket Options in my MQTT npm package.

var client = mqtt.connect('mqtt://test.mosquitto.org', {
  clientId: 'mqttjs_6fa3a7ee3d',
  wsOptions: {
  host: '100.84.81.28',
  port: 8083,
  path: '/mqtt'
}
});  

My EMQ connection with NodeJs.

var client = mqtt.connect('ws://100.84.81.28:8083/mqtt');
Abishek G
  • 11
  • 5
  • Bridges are created between brokers, not clients. The mosquitto.conf docs explain how to set it up to bridge to another broker – hardillb Nov 08 '18 at 11:28
  • Yes. Thats what i meant. I want to include my mosquitto.conf file in my nodejs code. How do i do that? – Abishek G Nov 08 '18 at 12:04
  • OK, so look at the man (https://mosquitto.org/man/mosquitto-conf-5.html) page for the conf file. Have a go and you can ask specific questions if you get stuck – hardillb Nov 08 '18 at 12:10
  • I use my mosquitto.conf file in my terminal and it works absolutely fine. Not able to include it in my nodejs where i am stuck. Not able to create a bridge between mosquitto and EMQx – Abishek G Nov 08 '18 at 12:19
  • @hardillb - Is my way of including the websocket URL right in my mosquitto options in the above code? Or is there any other way? – Abishek G Nov 08 '18 at 12:30
  • You haven't shown your mosquitto.conf so I don't know. Also you can't bridge using MQTT over Websockets, the bridge must use native MQTT – hardillb Nov 08 '18 at 12:47

1 Answers1

0

As said in the comments, bridges are something you have to configure in the broker, not the client.

The following will not work, you have told the client library to connect to the broker using native MQTT with the mqtt:// url prefix. This means it will totally ignore the wsOptions block in settings object.

var client = mqtt.connect('mqtt://test.mosquitto.org', {
  clientId: 'mqttjs_6fa3a7ee3d',
  wsOptions: {
  host: '100.84.81.28',
  port: 8083,
  path: '/mqtt'
}
}); 

Also you can't have the client try to connect to 2 separate brokers at once (You can have 2 separate client instances).

To configure a bridge you need to look at the mosquitto.conf doc, you will need to run your own instance of mosquitto, you can not use test.mosquitto.org as you can not change it's config. The bridge needs to be made using native MQTT, not MQTT over websockets.

hardillb
  • 54,545
  • 11
  • 67
  • 105