@@ -29,6 +29,17 @@ class AMQPClient {
29
29
this . logger = logger ;
30
30
}
31
31
32
+ async shutdown ( ) {
33
+ if ( this . channel ) {
34
+ await this . channel . close ( ) ;
35
+ this . logger . info ( 'The channel closed successfully' ) ;
36
+ }
37
+ if ( this . connection ) {
38
+ await this . connection . close ( ) ;
39
+ this . logger . info ( 'The connection closed successfully' ) ;
40
+ }
41
+ }
42
+
32
43
init ( confirmChannel = true , assertExchangeOptions , deleteQueue ) {
33
44
return new Promise ( ( resolve , reject ) => {
34
45
this . connection = amqp . connect ( [ this . cfg . amqpURI ] , {
@@ -61,14 +72,14 @@ class AMQPClient {
61
72
confirm : confirmChannel ,
62
73
setup : async ( channel ) => {
63
74
try {
64
- this . logger . debug ( 'Asserting topic exchange...') ;
75
+ this . logger . debug ( { exchange : this . cfg . topic } , 'Asserting exchange...') ;
65
76
await channel . assertExchange ( this . cfg . topic , 'topic' , assertExchangeOptions ) ;
66
77
if ( ! confirmChannel ) {
67
- this . logger . debug ( 'Asserting queue' ) ;
78
+ this . logger . debug ( { queueName : this . queueName } , 'Asserting queue' ) ;
68
79
await channel . assertQueue ( this . queueName , { exclusive : false , durable : false } ) ;
69
80
const keys = ( this . cfg . bindingKeys || '#' ) . split ( ',' ) . map ( ( s ) => s . trim ( ) ) ;
70
81
for ( const key of keys ) {
71
- this . logger . debug ( 'Binding queue to exchange...' ) ;
82
+ this . logger . debug ( { key , queueName : this . queueName , exchange : this . cfg . topic } , 'Binding queue to exchange...' ) ;
72
83
await channel . bindQueue ( this . queueName , this . cfg . topic , key ) ;
73
84
}
74
85
}
0 commit comments