Skip to content

This service monitors NATS subjects and then relay published messages to one of the following destinations: REST API or Another pub/sub destination (e.g. NATS, RabbitMQ, Kafka)

License

Notifications You must be signed in to change notification settings

tazama-lf/relay-service

Repository files navigation

Tazama Relay Service

Relay Service Documentation

Table of Contents

1. Component Overview

It is a TypeScript-based service that bridges communication between TMS (Tazama Monitoring Service) and client applications handling transaction processing and analysis.

1.1 An overview of the document and its purpose

This service acts as an intermediary, reading messages from a NATS server and forwarding them to various client-side message queue implementations, including RabbitMQ, REST API, or NATS. Its primary purpose is to facilitate seamless communication between TMS and transaction processing/analysis applications.

1.2 Features

  • Consumes NATS messages
  • Compatible with various output destinations: RabbitMQ, REST API, and NATS
  • Built using TypeScript for enhanced type safety and maintainability
  • Designed specifically for financial risk management and transaction processing scenarios

1.3 Major Functions

The Message Relaying Service offers several core functions that work together to enable efficient message forwarding. These functions are designed to handle different aspects of the message relaying process.

  • Start Function

typescript startRelayServices: () => Promise

The startRelayServices function initializes the service by setting up subscribers to read messages from the configured input source; leveraging frms-coe-startup-lib. After successful initialization, an execute function is provided (with a custom implementation) to be called whenever a NATS message is received. Ultimately, it is this execute function which will call the relay method to forward your message to the destination set in your environment

  • Relay Message Function

typescript relay: (message: Uint8Array) => Promise

This function acts as the central hub for message forwarding. It determines the appropriate destination service/messaging queue based on the (config.destinationType) and calls the corresponding relay function. The frms-coe-startup-lib supports RabbitMQ, NATS, and REST API.

2. System Architecture

This section provides an overview of how the Relay Service interacts with different components in the Tazama ecosystem. The diagrams illustrate the flow of messages from TazamaTP and TazamaTADP through the Relay Service to various destinations, such as NATS, RabbitMQ, or REST APIs.

2.1 Relay Service to NATS / RabbitMQ / REST API for TazamaTP

stateDiagram
    TazamaTP --> RelayService: Sends message to NATS Subject (Interdiction Service)
    RelayService --> Destination: Sends message to Destination i.e. NATS / RabbitMQ / REST API
Loading

2.2 Relay Service to NATS / RabbitMQ / REST API for TazamaTADP

stateDiagram
    TazamaTADP --> RelayService: Sends message to NATS Subject (CMS)
    RelayService --> Destination: Sends message to Destination i.e. NATS / RabbitMQ / REST API
Loading

3. Configuration

The service can be configured through environment variables or a configuration file. Refer to the .env.template.* or /config.ts file based on your requirement for available settings.

  • Environment Variables

The service can be configured using the following environment variables:

  • Init Variables

Variable Description
STARTUP_TYPE nats
NODE_ENV Node.js environment (e.g., production, development)
MAX_CPU CPU Limit for LoggerService
FUNCTION_NAME Name of the function associated with the relay service
CONSUMER_STREAM Name of the stream for the NATS consumer
  • Destination Variables

  1. Nats Producer Variables

Variable Description
DESTINATION_TYPE nats
DESTINATION_URL URL for the NATS destination
PRODUCER_STREAM Name of the stream for the NATS producer
  1. RabbitMQ Producer Variables

Variable Description
DESTINATION_TYPE rabbitmq
DESTINATION_URL URL for the RabbitMQ destination
Queue Name of the queue for the RabbitMQ producer
  1. RESTAPI Producer Variables

Variable Description
DESTINATION_TYPE rest
DESTINATION_URL URL for the REST API destination
JSON_PAYLOAD Delivery message as JSON (true/false)
MAX_SOCKETS Max http/https sockets limit (2500 by default)
  • APM Configuration

Variable Description
APM_ACTIVE Enables Elastic APM
APM_SERVICE APM Service name
APM_URL APM server URL
APM_SECRET_TOKEN APM Secret token
  • Logging Configuration

Variable Description
LOGSTASH_LEVEL Log level
SIDECAR_HOST Address that the event sidecar is listening on

4. Deployment Guide

  • Pre-requisites:

Before starting, ensure the following is in place: Docker is installed on your system. You have access to the repository that contains the Relay Service code. You have GH_TOKEN set in your environment.

  • Step-by-Step Deployment Instructions:

1. Clone the Repository

2. Open your terminal and run the following command to clone the repository:

git clone <repository-link>

3. Configure Environment Variables

Update the environment configuration file (.env) as per your system's requirements. Make sure to correctly configure any database or service connection details.

4. Build the Docker Image

Once the environment is configured, build the Docker image using the following command:

docker compose build -t your-image-name

5. Run the Docker Container

After building the image, start the service in detached mode (in the background) using the command:

docker compose up -d your-image-name

5. Running the Service

Once configured, the service will automatically start reading messages sent through NATS with the subject configured by CONSUMER_STREAM and forwarding them to the designated output destination. This process involves:

  1. Calling the startRelayServices() function to initialize subscribers and begin message reading.
  2. Processing incoming messages through the execute() function.
  3. Forwarding messages to the appropriate destination using the configured service.

The service continues to operate until manually stopped, continuously monitoring the input source and relaying messages as they arrive.

6. Contributor Information

For any queries or assistance regarding the Relay service, you can reach out to the following contributors:

About

This service monitors NATS subjects and then relay published messages to one of the following destinations: REST API or Another pub/sub destination (e.g. NATS, RabbitMQ, Kafka)

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published