@@ -103,10 +103,11 @@ class Notificator {
103
103
throw err ;
104
104
} finally {
105
105
await log . close ( ) ;
106
- this . notif_to_connect . clear ( ) ;
107
106
for ( const conn of this . connect_str_to_connection . values ( ) ) {
108
107
conn . destroy ( ) ;
109
108
}
109
+ this . connect_str_to_connection . clear ( ) ;
110
+ this . notif_to_connect . clear ( ) ;
110
111
}
111
112
}
112
113
}
@@ -272,18 +273,25 @@ class KafkaNotificator {
272
273
273
274
async connect ( ) {
274
275
this . connection = new Kafka . HighLevelProducer ( this . connect_obj . kafka_options_object ) ;
276
+ dbg . log2 ( "Kafka producer connecting, connect =" , this . connect_obj ) ;
275
277
await new Promise ( ( res , rej ) => {
276
278
this . connection . on ( 'ready' , ( ) => {
279
+ dbg . log2 ( "Kafka producer connected for connection =" , this . connect_obj ) ;
277
280
res ( ) ;
278
281
} ) ;
279
282
this . connection . on ( 'connection.failure' , err => {
283
+ dbg . error ( "Kafka producer failed to connect. connect = " , this . connect_obj , ", err =" , err ) ;
280
284
rej ( err ) ;
281
285
} ) ;
282
286
this . connection . on ( 'event.log' , arg => {
283
- dbg . log1 ( "event log" , arg ) ;
287
+ dbg . log2 ( "event log" , arg ) ;
288
+ } ) ;
289
+ this . connection . on ( 'event.error' , arg => {
290
+ dbg . error ( "event error =" , arg ) ;
284
291
} ) ;
285
292
this . connection . connect ( ) ;
286
293
} ) ;
294
+ dbg . log2 ( "Kafka producer's connect done, connect =" , this . connect_obj ) ;
287
295
this . connection . setPollInterval ( 100 ) ;
288
296
}
289
297
@@ -296,10 +304,12 @@ class KafkaNotificator {
296
304
Buffer . from ( JSON . stringify ( notif . notif ) ) ,
297
305
null ,
298
306
Date . now ( ) ,
299
- ( err , offset ) => {
307
+ err => {
300
308
if ( err ) {
309
+ dbg . error ( "Failed to notify. Connect =" , connect_obj , ", notif =" , notif ) ;
301
310
promise_failure_cb ( notif , failure_ctxt , err ) . then ( resolve ) ;
302
311
} else {
312
+ dbg . log2 ( "Kafka notify successful. Connect =" , connect_obj , ", notif =" , notif ) ;
303
313
resolve ( ) ;
304
314
}
305
315
}
@@ -308,8 +318,10 @@ class KafkaNotificator {
308
318
}
309
319
310
320
destroy ( ) {
311
- this . connection . flush ( 10000 ) ;
312
- this . connection . disconnect ( ) ;
321
+ if ( this . connection . isConnected ( ) ) {
322
+ this . connection . flush ( 10000 ) ;
323
+ this . connection . disconnect ( ) ;
324
+ }
313
325
}
314
326
}
315
327
0 commit comments