Replies: 1 comment
-
But I noticed that in your sample code, there is no listening for incoming messages. client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My javascript applicatin does not receive retained messages as expected from a emqx-server in cloud. When use the same credentials in MQTT-explorer, is floating in as normal.
The remote broker is a EMQx broker which is bridging mqtt from remote broker outside my control.
My config is belove:
`const clientId = 'mqttjs_' +new Date().getTime() + '_' +parseInt(Math.random() * 100);
const host = 'ws://mybroker.domain.io:8083/mqtt'
const options = {
keepalive: 60,
clientId: clientId,
username: 'username',
password: 'password',
protocolId: 'MQTT',
protocolVersion: 5,
clean: true,
reconnectPeriod: 1000,
connectTimeout: 30 * 1000,
will: {
topic: 'WillMsg',
payload: 'Connection Closed abnormally..!',
qos: 2,
retain: true
},
}
var subscribeOptions = {
qos: 2,
rap:true,
rh:true,
};
console.log('Connecting mqtt client')
const client = mqtt.connect(host, options)
client.on('error', (err) => {
console.log('Connection error: ', err)
client.end()
})
client.on('reconnect', () => {
console.log('Reconnecting...')
})
client.on('connect', () => {
console.log('Client connected(134):' + clientId)
client.subscribe('sub1/sub2/+/sub4/json',subscribeOptions);
})
`
Beta Was this translation helpful? Give feedback.
All reactions