我正在尝试从 Node JS 向 Amazon MQ 发布消息,但到目前为止我尝试过的所有库似乎都没有工作。
图书馆 1:
stomp-client
代码:
var Stomp = require('stomp-client');
var destination = '/topic/{new_topic}';
var client = new Stomp('{prefix}.amazonaws.com',
61614,
'{user}',
'{password}');
client.connect(function(sessionId) {
client.publish(destination, 'Oh herrow');
});
第一个库出错:
Emitted 'error' event at:
at StompFrameEmitter.<anonymous> (project_path\node_modules\stomp-client\lib\client.js:236:10)
at StompFrameEmitter.emit (events.js:182:13)
[... lines matching original stack trace ...]
at Socket.Readable.push (_stream_readable.js:219:10)
图书馆 2:
stompit
代码:
const stompit = require('stompit');
var connectOptions = {
'host': '{prefix}.amazonaws.com',
'port': 61614,
'connectHeaders':{
'host': '/',
'login': '{user}',
'passcode': '{password}',
'heart-beat': '5000,5000'
}
};
stompit.connect(connectOptions, function(error, client) {
if (error) {
console.log('connect error ' + error.message);
return;
}
var sendHeaders = {
'destination': '/topic/{new_topic}',
'content-type': 'text/plain'
};
var frame = client.send(sendHeaders);
frame.write('hello');
frame.end();
});
第二个库出错:connect error unexpected end of stream
我不确定我还能尝试什么,但我似乎被困在这里,因为错误消息甚至都不冗长,而且网上没有很多关于这个问题的信息。
我在亚马逊论坛上找到的唯一相关文章没有答案: https ://forums.aws.amazon.com/thread.jspa?messageID=831730&tstart=0