Skip to content

guligon90/poc-nats-healthcheck

Repository files navigation

poc-nats-healthcheck [WiP]

Proof of concept (POC) of NATS streaming server implementation, for healthcheck purposes, in both Docker Compose and Kubernetes environments.

0. Table of Contents

1. Getting started

In order to build the project, you must have already installed and configured in your workspace:

2. Setting up the NATS streaming server

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.

2.1. Docker Compose

2.1.1. Building and running

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

2.1.2. Monitoring

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.

2.2. Kubernetes

2.2.1. Domain mapping

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

2.2.2. Building and running

In order to build and run the whole kubernetes cluster via skaffold, just run in the terminal, at the project root:

skaffold dev

2.2.3. Monitoring

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.

3. Publishing and subscribing

  • 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

3.1. Installing packages

Just run:

npm install

3.2. Running

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:

multiple-pubs-subs

Table of Contents

About

POC of NATS streaming server pub/sub implementation, for healthcheck purposes, in both Docker Compose and Kubernetes environments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published