I'm testing my Backend and using a StatefullSet Cluster of 3 RabbitMQ replicas , and using a client to test the Backend with "15" Users per Second.
We're using the NPM Package of
"amqplib": "0.10.3"
After around 2
hours I get that all my RabbitMQ connections are getting closed , as follows:
After around those 2
hours I'm left with only a 4-5 active connections and the reset are idle
and then they become blocked.
Here is my RabbitMQ connection handling:
import * as amqplib from 'amqplib'
import { Connection } from "amqplib";
async createChannel() {
if (!this.connection) {
this.connection = await this.connect();
if (!this.connection) return;
this.connection.on('close', () => this.handleConnectionClosed('close', {}));
this.connection.on('error', (error) => this.handleConnectionClosed('error', { error }));
this.connection.on('block', (blocked) => this.handleConnectionClosed('block', { blocked }));
}
if (!this.connectionChannel) {
this.connectionChannel = await this.connection.createChannel().catch((error) => {
this.handleConnectionClosed('close', error)
});
await this.connectionChannel.prefetch(config.queue.concurrentMessages);
this.connectionError = null;
}
return this.connectionChannel;
}
And this is the Queues properties:
async init(): Promise<void> {
try {
this.setSettings();
this.queueName = this.settings?.serviceName;
await this.createRejectedMessagesExchange();
this.exchange = await this.createDirect(this.settings.exchangeName, {
durable: true,
autoDelete: false,
[this.settings.deadLetterExchangeHeaderKey]: this.settings.deadLetterExchangeName,
});
} catch (error) {
throw error;
}
}
Why are all the connection getting idle
or blocked
within this short period of time ?