【问题标题】:Errors with publishing messages to Amazon Queue using available node js libraries使用可用节点 js 库向 Amazon Queue 发布消息时出错
【发布时间】:2019-05-12 20:22:44
【问题描述】:

我正在尝试从 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

【问题讨论】:

    标签: node.js activemq stomp amazon-mq


    【解决方案1】:

    对我来说解决这个问题的方法是将 ssl 连接设置为 true,如下所示:

    const server_options = {
      host,
      port,
      ssl: true,
      connectHeaders: {
        host: '/',
        'accept-version': '1.1',
        'heart-beat': '0,0', // no heart beat
        login: user,
        passcode: pass,
      },
    };
    

    stomp+ssl 连接的端口必须设置为 61614。

    【讨论】:

      猜你喜欢
      • 2014-05-01
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 2020-08-14
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多