inceptum
Advanced tools
Comparing version 0.8.7 to 0.8.8
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { Connection, Channel } from 'amqplib'; | ||
@@ -35,2 +36,3 @@ import { Logger } from '../log/LogManager'; | ||
export declare abstract class RabbitmqClient { | ||
connectionClosedTimer: NodeJS.Timer; | ||
protected channel: Channel; | ||
@@ -56,2 +58,4 @@ protected connection: Connection; | ||
protected handleConnectionError(err?: any): void; | ||
private clearConnectionClosedTimer(); | ||
protected handleConnectionClosedDelayed(): Promise<void>; | ||
protected handleConnectionClosed(): Promise<void>; | ||
@@ -58,0 +62,0 @@ protected createChannel(): Promise<void>; |
@@ -60,3 +60,4 @@ "use strict"; | ||
if (err) { | ||
this.logger.error(err, 'Connection error. Ignoring'); | ||
this.logger.error(err, 'Connection error.'); | ||
this.handleConnectionClosedDelayed(); | ||
} | ||
@@ -67,3 +68,20 @@ else { | ||
} | ||
clearConnectionClosedTimer() { | ||
if (this.connectionClosedTimer) { | ||
clearTimeout(this.connectionClosedTimer); | ||
this.connectionClosedTimer = undefined; | ||
} | ||
} | ||
async handleConnectionClosedDelayed() { | ||
this.clearConnectionClosedTimer(); | ||
try { | ||
this.connection.close(); | ||
} | ||
catch (e) { | ||
this.logger.error(e, 'Got an error on the connection. Attempting to close just in case. Had an error'); | ||
} | ||
this.connectionClosedTimer = setTimeout(() => this.handleChannelClosed(), 500); | ||
} | ||
async handleConnectionClosed() { | ||
this.clearConnectionClosedTimer(); | ||
if (!this.closed) { | ||
@@ -70,0 +88,0 @@ // We haven't been explicitly closed, so we should reopen the channel |
{ | ||
"name": "inceptum", | ||
"version": "0.8.7", | ||
"version": "0.8.8", | ||
"description": "hipages take on the foundational library for enterprise-grade apps written in NodeJS", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
442271
6698