@mojaloop/bulk-api-adapter 17.2.2 → 17.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -335,6 +335,32 @@ const isConnected = async () => {
335
335
  return true
336
336
  }
337
337
 
338
+ /**
339
+ * @function isHealthy
340
+ *
341
+ * @description
342
+ * Gets the health for the broker using the consumer's isHealthy() method
343
+ * from central-services-stream which performs comprehensive checks:
344
+ * - isConnected() - basic connection status
345
+ * - isAssigned() - consumer has partition assignments
346
+ * - isPollHealthy() - last poll was within healthCheckPollInterval
347
+ * - getMetadataSync() - all subscribed topics exist in broker metadata
348
+ *
349
+ * @returns {Promise<boolean>} - true if healthy, false otherwise
350
+ */
351
+ const isHealthy = async () => {
352
+ try {
353
+ const healthy = await notificationConsumer.isHealthy()
354
+ if (!healthy) {
355
+ Logger.isWarnEnabled && Logger.warn('Notification consumer is not healthy')
356
+ }
357
+ return healthy
358
+ } catch (err) {
359
+ Logger.isWarnEnabled && Logger.warn(`isHealthy check failed: ${err.message}`)
360
+ return false
361
+ }
362
+ }
363
+
338
364
  /**
339
365
  * @function getJWSSigner
340
366
  *
@@ -358,5 +384,6 @@ module.exports = {
358
384
  startConsumer,
359
385
  processMessage,
360
386
  consumeMessage,
361
- isConnected
387
+ isConnected,
388
+ isHealthy
362
389
  }
@@ -32,15 +32,26 @@ const axios = require('axios')
32
32
  /**
33
33
  * @function getSubServiceHealthBroker
34
34
  *
35
- * @description Gets the health for the Notification broker
35
+ * @description
36
+ * Gets the health for the broker using the consumer's isHealthy() method
37
+ * from central-services-stream which performs comprehensive checks:
38
+ * - isConnected() - basic connection status
39
+ * - isAssigned() - consumer has partition assignments
40
+ * - isPollHealthy() - last poll was within healthCheckPollInterval
41
+ * - getMetadataSync() - all subscribed topics exist in broker metadata
42
+ *
36
43
  * @returns Promise<SubServiceHealth> The SubService health object for the broker
37
44
  */
38
45
  const getSubServiceHealthBroker = async () => {
39
46
  let status = statusEnum.OK
40
47
  try {
41
- await Notification.isConnected()
48
+ const isHealthy = await Notification.isHealthy()
49
+ if (!isHealthy) {
50
+ Logger.isDebugEnabled && Logger.debug('getSubServiceHealthBroker: consumer is not healthy')
51
+ status = statusEnum.DOWN
52
+ }
42
53
  } catch (err) {
43
- Logger.debug(`getSubServiceHealthBroker failed with error: ${err.message}.`)
54
+ Logger.isDebugEnabled && Logger.debug(`getSubServiceHealthBroker failed with error: ${err.message}.`)
44
55
  status = statusEnum.DOWN
45
56
  }
46
57
 
@@ -15,7 +15,7 @@ Test('health handler', (handlerTest) => {
15
15
 
16
16
  handlerTest.beforeEach(t => {
17
17
  sandbox = Sinon.createSandbox()
18
- sandbox.stub(Notification, 'isConnected')
18
+ sandbox.stub(Notification, 'isHealthy')
19
19
  sandbox.stub(axios, 'get')
20
20
  healthHandler = proxyquire('../../src/api/handlers/health', {})
21
21
  t.end()
@@ -29,7 +29,7 @@ Test('health handler', (handlerTest) => {
29
29
 
30
30
  handlerTest.test('/health should', healthTest => {
31
31
  healthTest.test('return the correct response when the health check is up', async test => {
32
- Notification.isConnected.resolves(true)
32
+ Notification.isHealthy.resolves(true)
33
33
  axios.get.resolves({ data: { status: 'OK' } })
34
34
  const expectedResponseCode = 200
35
35
  const {
@@ -41,7 +41,7 @@ Test('health handler', (handlerTest) => {
41
41
  })
42
42
 
43
43
  healthTest.test('return the correct response when the health check is up in API mode only (Config.HANDLERS_DISABLED=true)', async test => {
44
- Notification.isConnected.resolves(true)
44
+ Notification.isHealthy.resolves(true)
45
45
 
46
46
  Config.HANDLERS_DISABLED = true
47
47
  healthHandler = proxyquire('../../src/api/handlers/health', {})
@@ -57,7 +57,7 @@ Test('health handler', (handlerTest) => {
57
57
 
58
58
  healthTest.test('return the correct response when the health check is down', async test => {
59
59
  healthHandler = proxyquire('../../src/api/handlers/health', {})
60
- Notification.isConnected.throws(new Error('Error connecting to consumer'))
60
+ Notification.isHealthy.resolves(false)
61
61
  axios.get.resolves({ data: { status: 'OK' } })
62
62
  const expectedResponseCode = 502
63
63
  const {