hemerajs / hapi-hemera

Hapi plugin to integrate Hemera.
MIT License
16 stars 7 forks source link

Issue when running in different host PatternNotFound #13

Closed L-David closed 6 years ago

L-David commented 6 years ago

We have a Host where NATS server & a Hemera instance are exposed. This Hemera instance works great. But if we add other Hemera instances that are in other Host machines. Everything becomes really unstable. Sometimes the pattern is matched and return with whats expected but many other times it responds with a PatternNotFound: No action found for this pattern. We have added Timeout we also have added natsbroad & tracer logs to look if it was getting added and the service is getting added

But still, sometimes it finds an action sometimes it doesn't:

`const nats = require('nats').connect({ url: process.env.NATS_URL, user: process.env.NATS_USER, pass: process.env.NATS_PW });

const hemera = new Hemera(nats, { logLevel: 'info', childLogger: true, tag: 'test', timeout: 10000 });

hemera.use(HemeraJoi);

const start = async () => { try { await hemera.ready(); let Joi = hemera.joi; hemera.add( { topic: 'math', cmd: 'sub', a: Joi.number().required(), b: Joi.number().required() }, async function (req) { try { return = req.a - req.b; } catch (error) { console.error(error); return error; } } ); hemera.log.info('Service listening'); } catch (err) { hemera.log.error(err); process.exit(1); } };

start();`

L-David commented 6 years ago

Apparently the issue maybe on the topic if we use a topic across Hemera stack of services on different hosts machine sometime it cannot resolve the the action assign to that pattern. Is there any limitation on the topic use? Or should we used different pattern matching.

StarpTech commented 6 years ago

Hi @L-David, if you scale a service on multiple hosts you have to ensure that each service has the same set of patterns available otherwise you will run into a PatternNotFound issue because NATS will load balance all requests and it can't differentiate.

Is this the issue?

StarpTech commented 6 years ago

Closing due to inactivity