diff --git a/io/stomp/18-stomp.html b/io/stomp/18-stomp.html
index 779bcb4f..e17dfe16 100644
--- a/io/stomp/18-stomp.html
+++ b/io/stomp/18-stomp.html
@@ -128,6 +128,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -140,6 +156,10 @@
defaults: {
server: {required:true},
port: {value:61618,required:true,validate:RED.validators.number()},
+ protocolversion: {value:"1.0",required:true},
+ vhost: {},
+ reconnectretries: {value:0,required:true,validate:RED.validators.number()},
+ reconnectdelay: {value:100,required:true,validate:RED.validators.number()},
name: {}
},
credentials: {
diff --git a/io/stomp/18-stomp.js b/io/stomp/18-stomp.js
index b70a3b9c..3333898a 100644
--- a/io/stomp/18-stomp.js
+++ b/io/stomp/18-stomp.js
@@ -23,6 +23,10 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n);
this.server = n.server;
this.port = n.port;
+ this.protocolversion = n.protocolversion;
+ this.vhost = n.vhost;
+ this.reconnectretries = n.reconnectretries;
+ this.reconnectdelay = n.reconnectdelay;
this.name = n.name;
this.username = this.credentials.user;
this.password = this.credentials.password;
@@ -40,44 +44,33 @@ module.exports = function(RED) {
this.topic = n.topic;
this.serverConfig = RED.nodes.getNode(this.server);
- this.host = this.serverConfig.server;
- this.port = this.serverConfig.port;
- this.userid = this.serverConfig.username;
- this.password = this.serverConfig.password;
+ this.stompClientOpts = {
+ address: this.serverConfig.server,
+ port: this.serverConfig.port * 1,
+ user: this.serverConfig.username,
+ pass: this.serverConfig.password,
+ protocolVersion: this.serverConfig.protocolVersion,
+ reconnectOpts: {
+ retries: this.serverConfig.reconnectretries * 1,
+ delay: this.serverConfig.reconnectdelay * 1
+ }
+ };
+ if (this.serverConfig.vhost) {
+ this.stompClientOpts.vhost = this.serverConfig.vhost;
+ }
var node = this;
var msg = {topic:this.topic};
- var closing = false;
- node.client = new StompClient(node.host, node.port, node.userid, node.password, '1.0');
- node.status({fill:"grey",shape:"ring",text:"connecting"});
+ node.client = new StompClient(node.stompClientOpts);
- var doConnect = function() {
- node.client.connect(function(sessionId) {
- node.status({fill:"green",shape:"dot",text:"connected"});
- node.log('subscribed to: '+node.topic);
- node.client.subscribe(node.topic, function(body, headers) {
- try {
- msg.payload = JSON.parse(body);
- }
- catch(e) {
- msg.payload = body;
- }
- msg.headers = headers;
- msg.topic = node.topic;
- node.send(msg);
- });
- }, function(error) {
- node.status({fill:"grey",shape:"dot",text:"error"});
- node.warn(error);
- });
- }
+ node.client.on("connect", function() {
+ node.status({fill:"green",shape:"dot",text:"connected"});
+ });
- node.client.on("disconnect", function() {
- node.status({fill:"red",shape:"ring",text:"disconnected"});
- if (!closing) {
- setTimeout( function () { doConnect(); }, 15000);
- }
+ node.client.on("reconnecting", function() {
+ node.status({fill:"red",shape:"ring",text:"reconnecting"});
+ node.warn("reconnecting");
});
node.client.on("error", function(error) {
@@ -85,14 +78,31 @@ module.exports = function(RED) {
node.log(error);
});
- doConnect();
+ node.status({fill:"grey",shape:"ring",text:"connecting"});
+ node.client.connect(function(sessionId) {
+ node.log('subscribing to: '+node.topic);
+ node.client.subscribe(node.topic, function(body, headers) {
+ try {
+ msg.payload = JSON.parse(body);
+ }
+ catch(e) {
+ msg.payload = body;
+ }
+ msg.headers = headers;
+ msg.topic = node.topic;
+ node.send(msg);
+ });
+ }, function(error) {
+ node.status({fill:"grey",shape:"dot",text:"error"});
+ node.warn(error);
+ });
node.on("close", function(done) {
- closing = true;
if (node.client) {
- node.client.disconnect(function() { done(); });
+ // disconnect can accept a callback - but it is not always called.
+ node.client.disconnect();
}
- else { done(); }
+ done();
});
}
RED.nodes.registerType("stomp in",StompInNode);
@@ -104,34 +114,45 @@ module.exports = function(RED) {
this.topic = n.topic;
this.serverConfig = RED.nodes.getNode(this.server);
- this.host = this.serverConfig.server;
- this.port = this.serverConfig.port;
- this.userid = this.serverConfig.username;
- this.password = this.serverConfig.password;
+ this.stompClientOpts = {
+ address: this.serverConfig.server,
+ port: this.serverConfig.port * 1,
+ user: this.serverConfig.username,
+ pass: this.serverConfig.password,
+ protocolVersion: this.serverConfig.protocolVersion,
+ reconnectOpts: {
+ retries: this.serverConfig.reconnectretries * 1,
+ delay: this.serverConfig.reconnectdelay * 1
+ }
+ };
+ if (this.serverConfig.vhost) {
+ this.stompClientOpts.vhost = this.serverConfig.vhost;
+ }
var node = this;
var msg = {topic:this.topic};
- var closing = false;
- node.client = new StompClient(node.host, node.port, node.userid, node.password, '1.0');
+ node.client = new StompClient(node.stompClientOpts);
node.status({fill:"grey",shape:"ring",text:"connecting"});
- node.client.connect( function(sessionId) {
- node.status({fill:"green",shape:"dot",text:"connected"});
- }, function(error) {
+ node.client.on("connect", function() {
+ node.status({fill:"green",shape:"dot",text:"connected"});
+ });
+
+ node.client.on("reconnecting", function() {
+ node.status({fill:"red",shape:"ring",text:"reconnecting"});
+ node.warn("reconnecting");
+ });
+
+ node.client.on("error", function(error) {
node.status({fill:"grey",shape:"dot",text:"error"});
node.warn(error);
});
- node.client.on("disconnect", function() {
- node.status({fill:"red",shape:"ring",text:"disconnected"});
- if (!closing) {
- setTimeout( function () { node.client.connect(); }, 15000);
- }
- });
-
- node.client.on("error", function(error) {
- node.log(error);
+ node.client.connect(function(sessionId) {
+ }, function(error) {
+ node.status({fill:"grey",shape:"dot",text:"error"});
+ node.warn(error);
});
node.on("input", function(msg) {
@@ -139,11 +160,11 @@ module.exports = function(RED) {
});
node.on("close", function(done) {
- closing = true;
if (node.client) {
- node.client.disconnect(function() { done(); });
+ // disconnect can accept a callback - but it is not always called.
+ node.client.disconnect();
}
- else { done(); }
+ done();
});
}
RED.nodes.registerType("stomp out",StompOutNode);
diff --git a/io/stomp/package.json b/io/stomp/package.json
index fd620344..7430d70f 100644
--- a/io/stomp/package.json
+++ b/io/stomp/package.json
@@ -3,7 +3,7 @@
"version" : "0.0.7",
"description" : "A Node-RED node to publish and subscribe to/from a Stomp server",
"dependencies" : {
- "stomp-client" : "0.6.*"
+ "stomp-client" : "0.8.*"
},
"repository" : {
"type":"git",