alphonse92 / alphonse92/javascript-prerender

NATS - Microservice auto registering, discovery and messaging

Offen
#17 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
5
Forks
1
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

We need a way to register each microservice instead of a static registration. Also, we need to check the health of each microservice without using HTTP because it could get into a conflict with some microservice routes. Also, we need to create a way to add microservices to the ecosystem dynamically, sure, with a security basis.

In order to it, we need to add to the microservice ecosystem NATS. Also, we need to specify a protocol, interface o some way to:

1. Microservice register on startup.
2. The gateway must check the availability of a microservice using NATS, for this, the gateway must have a table (in memory) with the currently registered microservices. If a request target to a microservice that is not registered in the table, then the Gateway must check the availability sending a message with NATS. If the microservice respond, the gateway adds the microservice to the table.

# Security
First of all, the gateway is the only microservices that is enabled to manage the microservice routing. In order to keep a secure flow, we need to update the docker-compose yaml file to provides a unique JWT token, or a common secret. The Gateway must have a Secret always (it is a mandatory), this secret will be used to generate new tokens to new Microservices.

## Requirements to register to the ecosystem

1. Each microservice must have or a JWT token or a secret, otherwise the microservice will not be registered.
2. The gateway Must Have a secret. If it does not exist, the gateway CANT START.

# Way to register a microservice

1. At startup: Each microservice send a message with the 'secret' or the JWT token, and its name to the gateway. If MS sends a Secret, the gateway validates the secret and send a token. If the MS sends a token, the gateway must validate it, and if the token or the secret is valid, then Gateway must add it to the Microservices table

2. a request to unknow microservices arrives: It could be happend if that microservice was not registered in the microservices table. Then, the Gateway must send a message to identify (PING), if it was not resolved (because the microservice doest not exist, or it is not properly configured), send a 404. Otherwise, if the microservice exists and it is properly configured, the microservice will send the token or the secret, and it will be registered as above.

# Messages namming

#### "gateway:ping"

- Listen by: children microservices
- Sended by: gateway

is a gateway message to discovery new microservices.

#### "gateway:login"

- Listen By: gateway
- Sended by: microservices that want to register to the ecosystem
- Data: {name:'myMs', token?:'tokenOrSecret',secret:?'tokenOrSecret' } , token or secret must be sent.

add myMs to the microservice table

#### "gateway:logout"

- Listen By: gateway
- Sended by: microservices that want to be removed from the ecosystem
- Data: {name:'myMs', token?:'tokenOrSecret',secret:?'tokenOrSecret' }, token or secret must be sent.

remove myMs from the microservice table

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.