From 3d4622489f7948563b9776962b875eca366c3d66 Mon Sep 17 00:00:00 2001 From: Julien Zapata Duque Date: Fri, 5 Sep 2025 18:08:13 +0200 Subject: [PATCH 1/2] fix(amqp): remove event listener when channel is closed Fixes #202 --- lib/adapters/amqp.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/adapters/amqp.js b/lib/adapters/amqp.js index 1166f8c..d60c64d 100644 --- a/lib/adapters/amqp.js +++ b/lib/adapters/amqp.js @@ -36,9 +36,9 @@ module.exports = (config) => { }, { noAck: true } ) - // Publish the received message to the queue - app.on('sync-out', (data) => { - try { + + function publishToQueue(data) { + try { const publishResponse = channel.publish( key, queue, @@ -48,7 +48,16 @@ module.exports = (config) => { } catch (error) { debug(`Publish fail: |${error.message}| APMQ channel`) } + } + + // Publish the received message to the queue + app.on('sync-out', publishToQueue) + + channel.on('close', () => { + debug('Channel closed') + app.off('sync-out', publishToQueue) }) + return channel } catch (error) { debug(`Publish fail: |${error.message}| APMQ channel`) From fe39eb469efbd7a7742c4a5df14d1b3e58dbd3ce Mon Sep 17 00:00:00 2001 From: Julien Zapata Duque Date: Fri, 5 Sep 2025 18:08:38 +0200 Subject: [PATCH 2/2] refactor(amqp): fix typo in debug statements --- lib/adapters/amqp.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/adapters/amqp.js b/lib/adapters/amqp.js index d60c64d..00a2b74 100644 --- a/lib/adapters/amqp.js +++ b/lib/adapters/amqp.js @@ -30,7 +30,7 @@ module.exports = (config) => { queue, (message) => { if (message !== null) { - debug(`Got ${key} event from APMQ channel`) + debug(`Got ${key} event from AMQP channel`) app.emit('sync-in', message.content) } }, @@ -44,9 +44,9 @@ module.exports = (config) => { queue, Buffer.from(data) ) - debug(`Publish success: |${publishResponse}| APMQ channel`) + debug(`Publish success: |${publishResponse}| AMQP channel`) } catch (error) { - debug(`Publish fail: |${error.message}| APMQ channel`) + debug(`Publish fail: |${error.message}| AMQP channel`) } } @@ -60,7 +60,7 @@ module.exports = (config) => { return channel } catch (error) { - debug(`Publish fail: |${error.message}| APMQ channel`) + debug(`Publish fail: |${error.message}| AMQP channel`) } } })