Skip to content

Commit 000d823

Browse files
author
Sachin Maheshwari
committed
adding health endpoint for processor service
1 parent fdc6e42 commit 000d823

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
"sequelize": "^4.21.0",
5353
"superagent": "^3.8.0",
5454
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6",
55-
"winston": "^2.2.0"
55+
"winston": "^2.2.0",
56+
"topcoder-healthcheck-dropin": "^1.0.3"
5657
},
5758
"engines": {
5859
"node": "6.x"

src/app.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const logger = require('./common/logger');
1515
const errors = require('./common/errors');
1616
const models = require('./models');
1717
const Kafka = require('no-kafka');
18+
const healthcheck = require('topcoder-healthcheck-dropin')
1819

1920
/**
2021
* Start Kafka consumer for event bus events.
@@ -74,11 +75,25 @@ function startKafkaConsumer(handlers, notificationServiceHandlers) {
7475
});
7576
});
7677

78+
const check = function () {
79+
if (!consumer.client.initialBrokers && !consumer.client.initialBrokers.length) {
80+
return false
81+
}
82+
let connected = true
83+
consumer.client.initialBrokers.forEach(conn => {
84+
logger.debug(`url ${conn.server()} - connected=${conn.connected}`)
85+
connected = conn.connected & connected
86+
})
87+
return connected
88+
}
7789

7890
consumer
7991
.init()
80-
.then(() => _.each(_.keys(handlers),
81-
(topicName) => consumer.subscribe(topicName, dataHandler)))
92+
.then(() => {
93+
_.each(_.keys(handlers),
94+
(topicName) => consumer.subscribe(topicName, dataHandler))
95+
healthcheck.init([check])
96+
})
8297
.catch((err) => {
8398
logger.error('Kafka Consumer failed');
8499
logger.error(err);

0 commit comments

Comments
 (0)