NATS

Use of NATS on your local machine

NATS

Parro Nexus relies heavily on NATS for service 2 service communication. When you work on a service locally you will at some point need a working NATS environment for testing or running multiple services.

The Parro Nexus repo contains a NATS setup using docker which can (and should) be used when working on services. This setup uses the NATS docker container and adds some authorization en stream setup.

Prerequisites

You need to have docker installed on your machine in order to work with NATS.

Start a server

In the scripts directory of the Parro Nexus repo you will find a start_nats.sh script which will start a NATS docker container. The script will use the NATS config file found in docker/nats_conf.conf. This configuration file has a fixed authorization setup with a single Account (see Authentication chapter of NATS page). The credential files which work with this setup are:

  • ./nats-sys-user.creds - System user, for NATS maintenance
  • ./nats-test-user.creds - Actual user, for Parro Nexus services

The start_nats.sh script will also mount all config (./scripts/nats-box-scripts/config), sample messages (./scripts/nats-box-scripts/tools) and a setup (./scripts/nats-box-scripts/setup) script to a nats-box container. The nats-box container contains a NATS CLI which can be used to configurate and monitor the NATS server. When you run the start_nats.sh script you will end up in a shell within this nats-box container. Add this point you can run the setup command to run the ./scripts/nats-box-scripts/setup script. This will create all configuration required for Parro Nexus to run.

To test services you can use one of the sample messages in ./scripts/nats-box-scripts/tools. These are all added to the /usr/local/bin dir so you can just run them as commands:

  • dlq - Send a message to the connect.v1.dlq.ingester subject
  • error - Send a message to the connect.v1.error subject
  • get_org - Send a request to the organisation.v1.get_organisation subject
  • ingest - Send a message to the message.v1.ingest subject
  • invalid_msg - Send an invalid message to the message.v1.validate subject
  • prepared - Send a message to the message.v1.prepared subject
  • receipt - Send a message to the message.v1.receipt subject
  • valid_msg - Send a message to the message.v1.validate subject

Stop the server

To stop the server you can kill the running docker containers or run the stop_nats.sh script in the scripts directory.