1

I am trying to publish messages to Amazon MQ from Node JS and none of the libraries I have tried so far seem to be working.

Library 1:

stomp-client

Code:

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');
});

Error with first library:

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)

Library 2:

stompit

Code:

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();

});

Error with second library: connect error unexpected end of stream

I am not sure what else I can try but I seem to be stuck here as the error messages are not even verbose plus there isnt a lot of information on this issue online.

Only relevant article I found has no answer on Amazon forum: https://forums.aws.amazon.com/thread.jspa?messageID=831730&tstart=0

Nick Div
  • 5,338
  • 12
  • 65
  • 127

1 Answers1

1

What worked for me to solve this issue was to set ssl connection to true as follows:

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

Port must be set to 61614 for stomp+ssl connection.

josescuderoh
  • 65
  • 10