Proof of concept (POC) of NATS streaming server implementation, for healthcheck purposes, in both Docker Compose and Kubernetes environments.
In order to build the project, you must have already installed and configured in your workspace:
The NATS streaming server can be built and run either by Docker Compose or Kubernetes. You can follow one the instructions below, for each environment.
To build the image for the nats
service, execute:
docker-compose build --pull nats
With the image built, to run the container and see its logs, run in the terminal:
docker-compose up -d nats && docker-compose logs --follow nats
With all the deployment finished and the pods created, the interface for monitoring the NATS streaming server can be accessed via browser at http://localhost:8222/streaming
.
There are some scripts that must be run in order to setup some configurations concerning domain mapping. In the terminal, run the following commands:
cd infra/k8s/scripts
./manage-domain.sh add # Maps the nats-healthcheck domain to the minikube IP (in /etc/hosts)
For removing such settings, just run:
./manage-domain.sh remove
In order to build and run the whole kubernetes cluster via skaffold, just run in the terminal, at the project root:
skaffold dev
With all the deployment finished and the pods created, the interface for monitoring the NATS streaming server can be accessed via browser at http://nats-healthcheck/streaming
.
src/publisher.ts
: Creates a connection to the streaming server and sends a stringified JSON containing the PID and the uptime of the current process, every 30 seconds;src/listener.ts
: Creates a connection and a subscription to the same channel
The configuration parameters, such as publishing interval, subject (channel name), can be modified in src/common/constants.ts
Just run:
npm install
In order to test multiple instances of publishers and subscribers, for different terminal instances, you can run:
npm run publish # Runs the publisher
In another terminal, run:
npm run listen # Runs the listener
The following image ilustrates two instances of publishers and two instances of subscribers in operation: