1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

STOMP bugfix: usage of multiple stomp in nodes (#1015)

* Bugfix: only execute node register callbacks after connection to the server has been made

* Bugfix: only execute direct callback of register node register when connected to STOMP server

* Doc: Add tip about reconnection to server
This commit is contained in:
Olivier Verhaegen 2023-07-11 20:58:51 +02:00 committed by GitHub
parent a2b7e1a30c
commit 45b43ebb21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -16,7 +16,7 @@
<option value="client-individual">Client individual (only v1.1)</option>
</select>
</div>
<div class="form-tips">
<div class="form-tips" style="margin-bottom: 12px;">
Enabling the ACK (acknowledgment) will set the <code>ack</code> header to <code>client</code> while subscribing to topics.
This means the items on the broker queue will not be dequeue'd unless an ACK message is sent using the <code>ack</code> node.
</div>
@ -73,7 +73,7 @@
<label for="node-input-name" style="width: 110px;"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-tips">The <b>Destination</b> field is optional. If not set uses the <code>msg.topic</code>
<div class="form-tips" style="margin-bottom: 12px;">The <b>Destination</b> field is optional. If not set uses the <code>msg.topic</code>
property of the message.</div>
</script>
@ -147,6 +147,9 @@
<label for="node-config-input-reconnectdelay"><i class="fa fa-clock-o"></i> Reconnect Delay (S)</label>
<input type="number" id="node-config-input-reconnectdelay" />
</div>
<div class="form-tips" style="margin-bottom: 12px;">
Reconnection timings are calculated using exponential backoff. The first reconnection happens immediately, the second reconnection happens at +delay ms, the third at + 2*delay ms, etc.
</div>
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-config-input-name" placeholder="Name">

View File

@ -84,6 +84,8 @@ module.exports = function(RED) {
node.sessionId = null;
node.subscribtionIndex = 1;
node.subscriptionIds = {};
/** Array of callbacks to be called once the connection to the broker has been made */
node.connectedCallbacks = [];
/** @type { StompClient } */
node.client;
node.setOptions = function(options, init) {
@ -134,10 +136,20 @@ module.exports = function(RED) {
*/
node.register = function(stompNode, callback = () => {}) {
node.users[stompNode.id] = stompNode;
if (!node.connected) {
node.connectedCallbacks.push(callback);
}
// Auto connect when first STOMP processing node is added
if (Object.keys(node.users).length === 1) {
node.connect(callback);
} else {
node.connect(() => {
while (node.connectedCallbacks.length) {
node.connectedCallbacks.shift().call();
}
});
} else if (node.connected) {
// Execute callback directly as the connection to the STOMP server has already been made
callback();
}
}