hemerajs / hapi-hemera

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

Cluester NATS detaction #11

Closed L-David closed 6 years ago

L-David commented 6 years ago

Hello, I have several mirrored services in docker on different servers with (NATS / Hemera) and a Hapi service connected to them.

The problem: If I defined only a NATS 'server' URL in Hapi nats plugin: it can heal a Hemera shutdown, but it fails if the NATS instance referenced in the 'server' property is shutdown and even after restarting that NATS instance it can't heal the service. Now the problem is that I don't know all the NATS URLs instances that will exist at the time of startup (there can be added after the startup), so what I expected was to be able to pass the NATS master instance URL and get all the other instances as they were added to the cluster pool.

Note: The code is strongly based on the aither project. with some adjustments to separate the services of NATS / HEMERA / REDDIS in some containers and HapiHemera in another running on different servers. F5 is used for load balancing

HAPI code: ` const servers = [ 'http://50.21.176.103:4222' ];

const server = new Hapi.Server({ port: process.env.API_PORT, host: process.env.API_HOST, debug: { request: ['error'] } });

async function start() { await server.register([ { plugin: HapiHemera, options: { hemera: { name: 'test', logLevel: process.env.HEMERA_LOG_LEVEL, childLogger: true, tag: 'hemera-1' }, nats: { servers: servers, user: process.env.NATS_USER, pass: process.env.NATS_PW }, plugins: [require('hemera-joi')] } }, Inert ]);`

I don't know if it's possible or if it's the right way of doing a distributed system. For now, the only solutions I can see is to, every time a NATS instance is shutdown I restart the HapiHemera (that works as a webserver) instance and force F5 to redirect a client to another instance of HapiHemera.

StarpTech commented 6 years ago

Closing due to inactivity