mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-08-29 02:36:11 -06:00
improve rabbit controller
This commit is contained in:
parent
4681576cfc
commit
b325500310
@ -45,7 +45,7 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
heartbeat: 30, // Add heartbeat of 30 seconds
|
heartbeat: 30, // Add heartbeat of 30 seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
amqp.connect(connectionOptions, (error, connection) => {
|
amqp.connect(connectionOptions, (error: Error, connection: amqp.Connection) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
local: 'RabbitmqController.connect',
|
local: 'RabbitmqController.connect',
|
||||||
@ -57,7 +57,7 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connection event handlers
|
// Connection event handlers
|
||||||
connection.on('error', (err) => {
|
connection.on('error', (err: Error) => {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
local: 'RabbitmqController.connectionError',
|
local: 'RabbitmqController.connectionError',
|
||||||
message: 'RabbitMQ connection error',
|
message: 'RabbitMQ connection error',
|
||||||
@ -71,7 +71,7 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
this.handleConnectionLoss();
|
this.handleConnectionLoss();
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.createChannel((channelError, channel) => {
|
connection.createChannel((channelError: Error, channel: amqp.Channel) => {
|
||||||
if (channelError) {
|
if (channelError) {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
local: 'RabbitmqController.createChannel',
|
local: 'RabbitmqController.createChannel',
|
||||||
@ -83,7 +83,7 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Channel event handlers
|
// Channel event handlers
|
||||||
channel.on('error', (err) => {
|
channel.on('error', (err: Error) => {
|
||||||
this.logger.error({
|
this.logger.error({
|
||||||
local: 'RabbitmqController.channelError',
|
local: 'RabbitmqController.channelError',
|
||||||
message: 'RabbitMQ channel error',
|
message: 'RabbitMQ channel error',
|
||||||
@ -136,8 +136,7 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
return; // Already attempting to reconnect
|
return; // Already attempting to reconnect
|
||||||
}
|
}
|
||||||
|
|
||||||
this.amqpChannel = null;
|
this.cleanup();
|
||||||
this.amqpConnection = null;
|
|
||||||
this.scheduleReconnect();
|
this.scheduleReconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,4 +405,25 @@ export class RabbitmqController extends EventController implements EventControll
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async cleanup(): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (this.amqpChannel) {
|
||||||
|
await this.amqpChannel.close();
|
||||||
|
this.amqpChannel = null;
|
||||||
|
}
|
||||||
|
if (this.amqpConnection) {
|
||||||
|
await this.amqpConnection.close();
|
||||||
|
this.amqpConnection = null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.warn({
|
||||||
|
local: 'RabbitmqController.cleanup',
|
||||||
|
message: 'Error during cleanup',
|
||||||
|
error: error.message || error,
|
||||||
|
});
|
||||||
|
this.amqpChannel = null;
|
||||||
|
this.amqpConnection = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user