Wednesday, 5 April 2017

Sending data to ActiveMQ via node.js/stompit

hope someone out there can help me on this one!

Task: Send xml files to ActiveMQ.

Environments:

Developing:

  • OS X 10.10.5
  • node 4.4.3
  • stompit 0.25.0

Production:

  • Ubuntu 16.04
  • node 7.8.0 (tried 4.4.3 too with same results)
  • stompit 0.25.0

I'm always connecting this way.

var server1 = { 'host': 'activemq-1.server.lan' };
var server2 = { 'host': 'activemq-2.server.lan' };
var servers = [server1, server2];
var reconnectOptions = { 'maxReconnects': 10 };
var manager = new stompit.ConnectFailover(servers, reconnectOptions);

Headers, i set for each frame:

const sendHeaders = {
    'destination'   : '/queue/name_of_queue',
    'content-type'  : 'text/plain',
    'persistent'    : 'true'
};

I'm not allowed to set the content-length header, as this would force the server to interpret the stream as a binary stream.

When connected to the server, i connect to a PostgreSQL server to fetch the data to send.

What works:

var frame = client.send(sendHeaders);
frame.write(row.pim_content);
frame.end();

But it only works at the developing machine. When running this in production environment, the script runs without throwing errors, but never sends the message to the server.

So I tried a different method, just to have a callback when the server receives a message.

var channel = new stompit.Channel(manager);
channel.send(sendHeaders, xml_content, (err)=>{ 
    if(err){
        console.log(err); 
    } else {
        console.log('Message successfully transferred');
    }
});

Now i get the same results for production and development. It is working as expected, but ...

It only works as long as the body (xml_content) has a maximum length of 1352 characters. When adding an additional character, the callback of channel.send() is never going to be fired.

I'm running out of ideas what to check/test next to get that thing working. I hope someone is reading this, laughing and pointing me to the right direction. Any ideas greatly appreciated!

Thanks in advance, Stefan



via Stefan

No comments:

Post a Comment