hemerajs / hemera

🔬 Writing reliable & fault-tolerant microservices in Node.js https://hemerajs.github.io/hemera/
MIT License
806 stars 70 forks source link

stats plugin not returning all actions #217

Closed esatterwhite closed 6 years ago

esatterwhite commented 6 years ago

Description

I 'm using the stats plugin in various services and trying to get all of the registered actions, but it seems to only return the actions from a one of the services in a cluster. I'll only get the actions from Service A, or Service B, or Service C rather than the actions for Service A + B+ C.

Expected Result

actions from every service are returned

Actual Result

actions list are from one and only one of the connected services

Context

Your Environment

StarpTech commented 6 years ago

Hi @esatterwhite if you call

hemera.act(
  {
    topic: 'stats',
    cmd: 'registeredActions',
    maxMessages$: -1
  },
  function(err, resp) {
    // is called multiple times
  }
)

you will receive multiple responses with the different actions from the services. You have to aggregate by yourself.

If you still get only the actions from one service then it could be a race condition or the plugin is not configured properly.

esatterwhite commented 6 years ago

Oh interesting. Is there a way to know when all of the services have responded?

StarpTech commented 6 years ago

This a pull mechanism. If you think that all service should send their information to a specific subscriber at startup, feel free to create PR.

StarpTech commented 6 years ago

Oh interesting. Is there a way to know when all of the services have responded?

You can't know it. You are able to start new services at any time. I prefer to implement a solution as suggested above.

StarpTech commented 6 years ago

@esatterwhite I implemented here https://github.com/hemerajs/hemera/pull/218 please review

StarpTech commented 6 years ago

After the PR you can just call

hemera.ready(() => {
    hemera.sendActionStats({
      topic: 'process.stats'
    })
})

in your services to inform your subscriber about new updates. This requires of course that your service process.stats is ready before the others.

StarpTech commented 6 years ago

Feature was published with hemera-stats@5.2.0