mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Updates to Stomp to enable auto reconnect, and node.status indicators
This commit is contained in:
parent
a320ddce23
commit
ae22efb270
@ -83,22 +83,42 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
var node = this;
|
var node = this;
|
||||||
var msg = {topic:this.topic};
|
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.host, node.port, node.userid, node.password, '1.0');
|
||||||
|
node.status({fill:"grey",shape:"ring",text:"connecting"},true);
|
||||||
|
|
||||||
|
var doConnect = function() {
|
||||||
node.client.connect(function(sessionId) {
|
node.client.connect(function(sessionId) {
|
||||||
|
node.status({fill:"green",shape:"dot",text:"connected"},true);
|
||||||
node.log('subscribed to: '+node.topic);
|
node.log('subscribed to: '+node.topic);
|
||||||
node.client.subscribe(node.topic, function(body, headers) {
|
node.client.subscribe(node.topic, function(body, headers) {
|
||||||
msg.payload = JSON.parse(body);
|
msg.payload = JSON.parse(body);
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
}, function(error) { node.warn(error); });
|
}, function(error) {
|
||||||
|
node.status({fill:"grey",shape:"dot",text:"error"},true);
|
||||||
|
node.warn(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
node.client.on("error", function(error) {
|
node.client.on("disconnect", function() {
|
||||||
node.log(error);
|
node.status({fill:"red",shape:"ring",text:"disconnected"},true);
|
||||||
|
node.log("disconnected at "+Date().toString());
|
||||||
|
if (!closing) {
|
||||||
|
setTimeout( function () { doConnect(); }, 15000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
node.client.on("error", function(error) {
|
||||||
|
node.status({fill:"grey",shape:"dot",text:"error"},true);
|
||||||
|
node.log("error: "+error);
|
||||||
|
});
|
||||||
|
|
||||||
|
doConnect();
|
||||||
|
|
||||||
node.on("close", function(done) {
|
node.on("close", function(done) {
|
||||||
|
closing = true;
|
||||||
if (node.client) {
|
if (node.client) {
|
||||||
node.client.on("disconnect", function() {
|
node.client.on("disconnect", function() {
|
||||||
done();
|
done();
|
||||||
@ -124,10 +144,25 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
var node = this;
|
var node = this;
|
||||||
var msg = {topic:this.topic};
|
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.host, node.port, node.userid, node.password, '1.0');
|
||||||
|
node.status({fill:"grey",shape:"ring",text:"connecting"},true);
|
||||||
|
|
||||||
node.client.connect();
|
node.client.connect( function(sessionId) {
|
||||||
|
node.status({fill:"green",shape:"dot",text:"connected"},true);
|
||||||
|
}, function(error) {
|
||||||
|
node.status({fill:"grey",shape:"dot",text:"error"},true);
|
||||||
|
node.warn(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
node.client.on("disconnect", function() {
|
||||||
|
node.status({fill:"red",shape:"ring",text:"disconnected"},true);
|
||||||
|
node.log("disconnected at "+Date().toString());
|
||||||
|
if (!closing) {
|
||||||
|
setTimeout( function () { node.client.connect(); }, 15000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
node.client.on("error", function(error) {
|
node.client.on("error", function(error) {
|
||||||
node.log(error);
|
node.log(error);
|
||||||
@ -138,6 +173,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
node.on("close", function(done) {
|
node.on("close", function(done) {
|
||||||
|
closing = true;
|
||||||
if (client) { client.disconnect(); }
|
if (client) { client.disconnect(); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user