我正在nodejs上使用包mqtt,使用服务创建的Amazon MQ提供的端点连接到mqtt协议的Amazon MQ。
连接始终返回“关闭”,从未建立。 我还不得不将端点用于wss,但没有成功。
`var mqtt = require('mqtt')
var options = {
username: 'xxxxxxxx',
password: 'xxxxxxxxxxx',
clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8)
};
//var client = mqtt.connect(options);
var client = mqtt.connect( 'mqtt+ssl://b-df60eddf-2351-426e-92a3-6c4fdc03445f-1.mq.us-west-2.amazonaws.com:8883', options);
client.on("error",function(error){
console.log("Error :" + error);
process.exit(1)
});
client.on("disconnect",function(error){
console.log("You are Disconnected ....." + error);
process.exit(1)
});
client.on("end",function(error){
console.log("You are ended ....." + error);
process.exit(1)
});
client.on("close",function(){
console.log("You are closed .....");
process.exit(1)
});
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
`
如果可能的话,有人可以帮助我。