How to write a sender application for ActiveMQ in Node JS
activemq-classic, java, node.js, stomp
Solution
You can try the activemq-node module, or you can enable the STOMP protocol on ActiveMQ and use this node.js library.
Problem
I wanted to create implement a JMS sender app for messaging and created the same with JAVA. This is my sample code snippet in Java. ``` try { factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); connection = factory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = session.createQueue("SAMPLEQUEUE"); producer = session.createProducer(destination); try { TextMessage message = session.createTextMessage(); message.setText("hello"); producer.send(message); System.out.println("Sent: " + message.getText()); } catch (IOException e) { e.printStackTrace(); } } catch (JMSException e) { e.printStackTrace(); } ``` This works fine and I am able to receive the messages with my receiver also. I want to change the sender implementation in Node JS and make it a Node JS application. I am new to Node JS didn't understand much after searching on ActiveMQ in Node JS. Any pointer to it would be really helpful. Regards, Subhankar EDIT I used stomp for node JS. The sample code is the following : ``` var Stomp = require('stomp-client'); var destination = '/queue/sensorstreamqueue'; var client = new Stomp('10.53.219.153', 61613, 'user', 'pass'); var lazy = require("lazy"), fs = require("fs"); client.connect(function(sessionId) { new lazy(fs.createReadStream('input.csv')) .lines .forEach(function(line){ client.publish(destination, line.toString()); } ); console.log("published"); }); ``` The code works and my receiver also gets the message but then my receiver expects it to be a textMesssage format and gives the following error: ``` 02-19-2015 08:42:31.288 ERROR [Thread-25] (JmsInputTransporter.handleTextMessage) Error code:401306, Severity : 3 (Error) Error message:JMS Transporter is expected a TextMessage, received class org.apache.activemq.command.ActiveMQBytesMessage. Error description:JMS Transporter is expected a TextMessage, received class org.apache.activemq.command.ActiveMQBytesMessage. ``` Can someone help me how can I achieve that?