feat(RabbitMQ Trigger Node): Automatically reconnect on disconnect (#4019)

* feat(RabbitMQ Trigger Node): Automatically reconnect on disconnect

*  Retry indefinetly

*  Also automatically retry activation issues on startup
This commit is contained in:
Jan Oberhauser
2022-09-29 11:50:18 +02:00
committed by GitHub
parent de4dd53a53
commit 23bd71b82a
6 changed files with 145 additions and 12 deletions

View File

@@ -17,8 +17,6 @@ import { rabbitDefaultOptions } from './DefaultOptions';
import { MessageTracker, rabbitmqConnectQueue } from './GenericFunctions';
import * as amqplib from 'amqplib';
export class RabbitMQTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'RabbitMQ Trigger',
@@ -181,12 +179,19 @@ export class RabbitMQTrigger implements INodeType {
const messageTracker = new MessageTracker();
let consumerTag: string;
let closeGotCalled = false;
const startConsumer = async () => {
if (parallelMessages !== -1) {
channel.prefetch(parallelMessages);
}
channel.on('close', () => {
if (!closeGotCalled) {
self.emitError(new Error('Connection got closed unexpectedly'));
}
});
const consumerInfo = await channel.consume(queue, async (message) => {
if (message !== null) {
try {
@@ -270,6 +275,7 @@ export class RabbitMQTrigger implements INodeType {
// The "closeFunction" function gets called by n8n whenever
// the workflow gets deactivated and can so clean up.
async function closeFunction() {
closeGotCalled = true;
try {
return messageTracker.closeChannel(channel, consumerTag);
} catch (error) {