From b91aa6a506f1896953eafe53ca619381de222541 Mon Sep 17 00:00:00 2001 From: Olivier Verhaegen <56387556+OlivierVerhaegen@users.noreply.github.com> Date: Wed, 12 Apr 2023 13:27:56 +0200 Subject: [PATCH] Use shared client connection --- io/stomp/18-stomp.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/io/stomp/18-stomp.js b/io/stomp/18-stomp.js index 4db8fef8..067cb4bf 100644 --- a/io/stomp/18-stomp.js +++ b/io/stomp/18-stomp.js @@ -16,6 +16,7 @@ module.exports = function(RED) { this.name = n.name; this.username = this.credentials.user; this.password = this.credentials.password; + this.clientConnection = null; } RED.nodes.registerType("stomp-server",StompServerNode,{ credentials: { @@ -57,7 +58,11 @@ module.exports = function(RED) { var node = this; var msg = {topic:this.topic}; - node.client = new StompClient(node.stompClientOpts); + // Save the client connection to the shared server instance if needed + if (!node.server.clientConnection) { + node.server.clientConnection = new StompClient(node.stompClientOpts); + } + node.client = node.server.clientConnection; node.client.on("connect", function() { node.status({fill:"green",shape:"dot",text:"connected"}); @@ -128,7 +133,11 @@ module.exports = function(RED) { } var node = this; - node.client = new StompClient(node.stompClientOpts); + // Save the client connection to the shared server instance if needed + if (!node.server.clientConnection) { + node.server.clientConnection = new StompClient(node.stompClientOpts); + } + node.client = node.server.clientConnection; node.client.on("connect", function() { node.status({fill:"green",shape:"dot",text:"connected"}); @@ -193,7 +202,11 @@ module.exports = function(RED) { // only start connection etc. when acknowledgements are configured to be send by client if (node.serverConfig.ack) { - node.client = new StompClient(node.stompClientOpts); + // Save the client connection to the shared server instance if needed + if (!node.server.clientConnection) { + node.server.clientConnection = new StompClient(node.stompClientOpts); + } + node.client = node.server.clientConnection; node.client.on("connect", function() { node.status({fill:"green",shape:"dot",text:"connected"});