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

STOMP: improved logging (#1010)

* Improvements to logging

* Subscribe log clarification

* Session id on connect fix
This commit is contained in:
Olivier Verhaegen 2023-06-21 21:18:59 +02:00 committed by GitHub
parent edd521f2e9
commit 1216ee5296
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,14 +184,15 @@ module.exports = function(RED) {
node.client = new StompClient(node.options); node.client = new StompClient(node.options);
node.client.on("connect", function() { node.client.on("connect", function(sessionId) {
node.closing = false; node.closing = false;
node.connecting = false; node.connecting = false;
node.connected = true; node.connected = true;
callback(); node.sessionId = sessionId;
node.log("Connected to STOMP server", {sessionId: node.sessionId, url: `${node.options.address}:${node.options.port}`, protocolVersion: node.options.protocolVersion}); node.log(`Connected to STOMP server, sessionId: ${node.sessionId}, url: ${node.options.address}:${node.options.port}, protocolVersion: ${node.options.protocolVersion}`);
setStatusConnected(node, true); setStatusConnected(node, true);
callback();
}); });
node.client.on("reconnect", function(sessionId, numOfRetries) { node.client.on("reconnect", function(sessionId, numOfRetries) {
@ -199,10 +200,10 @@ module.exports = function(RED) {
node.connecting = false; node.connecting = false;
node.connected = true; node.connected = true;
node.sessionId = sessionId; node.sessionId = sessionId;
callback();
node.log("Reconnected to STOMP server", {sessionId: node.sessionId, url: `${node.options.address}:${node.options.port}`, protocolVersion: node.options.protocolVersion, retries: numOfRetries}); node.log(`Reconnected to STOMP server, sessionId: ${node.sessionId}, url: ${node.options.address}:${node.options.port}, protocolVersion: ${node.options.protocolVersion}, retries: ${numOfRetries}`);
setStatusConnected(node, true); setStatusConnected(node, true);
callback();
}); });
node.client.on("reconnecting", function() { node.client.on("reconnecting", function() {
@ -219,10 +220,7 @@ module.exports = function(RED) {
setStatusError(node, true); setStatusError(node, true);
}); });
node.client.connect(function(sessionId) { node.client.connect();
node.sessionId = sessionId;
});
} catch (err) { } catch (err) {
node.error(err); node.error(err);
} }
@ -258,14 +256,13 @@ module.exports = function(RED) {
// Disconnection already in progress or not connected // Disconnection already in progress or not connected
callback(); callback();
} else { } else {
node.log("Unsubscribing from STOMP queue's...");
const subscribedQueues = Object.keys(node.subscriptionIds); const subscribedQueues = Object.keys(node.subscriptionIds);
subscribedQueues.forEach(function(queue) { subscribedQueues.forEach(function(queue) {
node.unsubscribe(queue); node.unsubscribe(queue);
}); });
node.log('Disconnecting from STOMP server...'); node.log('Disconnecting from STOMP server...');
waitDisconnect(node.client, 2000).then(() => { waitDisconnect(node.client, 2000).then(() => {
node.log("Disconnected from STOMP server", {sessionId: node.sessionId, url: `${node.options.address}:${node.options.port}`, protocolVersion: node.options.protocolVersion}) node.log(`Disconnected from STOMP server, sessionId: ${node.sessionId}, url: ${node.options.address}:${node.options.port}, protocolVersion: ${node.options.protocolVersion}`)
}).catch(() => { }).catch(() => {
node.log("Disconnect timeout closing node..."); node.log("Disconnect timeout closing node...");
}).finally(() => { }).finally(() => {
@ -287,7 +284,7 @@ module.exports = function(RED) {
* @param { Function } callback * @param { Function } callback
*/ */
node.subscribe = function(queue, acknowledgment, callback) { node.subscribe = function(queue, acknowledgment, callback) {
node.log(`Subscribing to: ${queue}`); node.log(`Subscribe to: ${queue}`);
if (node.connected && !node.closing) { if (node.connected && !node.closing) {
if (!node.subscriptionIds[queue]) { if (!node.subscriptionIds[queue]) {
@ -323,7 +320,7 @@ module.exports = function(RED) {
delete node.subscriptionIds[queue]; delete node.subscriptionIds[queue];
if (node.connected && !node.closing) { if (node.connected && !node.closing) {
node.client.unsubscribe(queue, headers); node.client.unsubscribe(queue, headers);
node.log(`Unsubscribed from ${queue}`, headers); node.log(`Unsubscribed from ${queue}, headers: ${JSON.stringify(headers)}`);
} }
} }