@@ -40,19 +40,25 @@ const init = async () => {
40
40
response_status_code : status ,
41
41
// check_interval_in_seconds: 86400,
42
42
}
43
- const result = await producer . send ( {
44
- topic,
45
- messages : [
46
- {
47
- // TODO: add logic for partitioning of messages
48
- partition : 1 , // if not specified, msg will be sent based on key
49
- key : 'heartbeat' , // if not specified, msg will be sent in round-robin fashion
50
- value : JSON . stringify ( data ) ,
51
- } ,
52
- ] ,
53
- } )
54
- logger . info ( `Message sent` , { msg : data , res : result } )
55
- await producer . disconnect ( ) // performs clean exit
43
+ producer
44
+ . send ( {
45
+ topic,
46
+ messages : [
47
+ {
48
+ // TODO: add logic for partitioning of messages
49
+ partition : 1 , // if not specified, msg will be sent based on key
50
+ key : 'heartbeat' , // if not specified, msg will be sent in round-robin fashion
51
+ value : JSON . stringify ( data ) ,
52
+ } ,
53
+ ] ,
54
+ } )
55
+ . then ( ( res ) => {
56
+ logger . info ( `Producer Send Result:` , { msg : data , res } )
57
+ } )
58
+ . catch ( ( err ) => logger . error ( `Producer Send Error:` , { err } ) )
59
+ . finally ( async ( ) => {
60
+ await producer . disconnect ( ) // performs clean exit
61
+ } )
56
62
} catch ( error ) {
57
63
logger . error ( `Kafka producer error` , { error } )
58
64
process . exit ( 1 )
0 commit comments