Skip to content

Commit 7fe790b

Browse files
Merge pull request #36 from topcoder-platform/dev
add new feature - key
2 parents 2d9daa2 + 07515c0 commit 7fe790b

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ workflows:
7777
context : org-global
7878
filters:
7979
branches:
80-
only: ['dev']
80+
only: ['dev', 'feature/shapeup3']
8181
- "build-prod":
8282
context : org-global
8383
filters:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Topcoder Bus API Server
22

3-
## Overview
3+
## Overview
44

55
A meta service, Topcoder Bus API server provides information about other services offered by Topcoder.
66

api/swagger.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,10 @@ definitions:
979979
type: "string"
980980
example: "application/json"
981981
description: "Mime-type for 'payload'.\n"
982+
key:
983+
type: "string"
984+
example: "abc123"
985+
description: "optional field to assure the one partition for 'payload'.\n"
982986
payload:
983987
type: "object"
984988
example:

common/helper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function validateEventPayload (event) {
133133
originator: Joi.string().required(),
134134
timestamp: Joi.string().required(),
135135
'mime-type': Joi.string().required(),
136+
key: Joi.string(),
136137
payload: Joi.any()
137138
})
138139
})

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)