December 2017
Intermediate to advanced
296 pages
5h 56m
English
Finally, we are going to look at the MQTT client integration with our api-engine. If we open api-engine/server/mqtt/index.js, we should see the default setup of the MQTTS client.
We are using the following configuration to connect to the Mosca broker over MQTTS:
var client = mqtt.connect({ port: config.mqtt.port, protocol: 'mqtts', host: config.mqtt.host, clientId: config.mqtt.clientId, reconnectPeriod: 1000, username: config.mqtt.clientId, password: config.mqtt.clientId, keepalive: 300, rejectUnauthorized: false});
And we are subscribing to two events: one when the connection is established and the other when we receive a message. On the connect event, we subscribe to a topic named greet and we are publishing a simple message ...