Skip to content

Commit 48d768b

Browse files
committed
fix: producer message send debug fix
1 parent 32d4cab commit 48d768b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

index.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,25 @@ const init = async () => {
4040
response_status_code: status,
4141
// check_interval_in_seconds: 86400,
4242
}
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+
})
5662
} catch (error) {
5763
logger.error(`Kafka producer error`, { error })
5864
process.exit(1)

0 commit comments

Comments
 (0)