Skip to content

Commit f78fde4

Browse files
author
Sachin Maheshwari
committed
adding support for publishing to kafka
1 parent f3ef65f commit f78fde4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

service/MessageBusService.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ async function postEvent (event) {
3030
helper.validateEventPayload(event)
3131

3232
// Post new structure
33-
const result = await producer.send({
33+
const message = {
34+
value: JSON.stringify(event)
35+
}
36+
if (event.key) {
37+
_.merge(message, { key: event.key })
38+
}
39+
const kafkaPayload = {
3440
topic: event.topic,
35-
message: {
36-
value: JSON.stringify(event)
37-
}
38-
})
41+
message
42+
}
43+
const result = await producer.send(kafkaPayload)
3944
// Check if there is any error
4045
const error = _.get(result, '[0].error')
4146
if (error) {

0 commit comments

Comments
 (0)