Table of Contents
- Tazama Relay Service
It is a TypeScript-based service that bridges communication between TMS (Tazama Monitoring Service) and client applications handling transaction processing and analysis.
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.
- 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
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.
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
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.
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.
stateDiagram
TazamaTP --> RelayService: Sends message to NATS Subject (Interdiction Service)
RelayService --> Destination: Sends message to Destination i.e. NATS / RabbitMQ / REST API
stateDiagram
TazamaTADP --> RelayService: Sends message to NATS Subject (CMS)
RelayService --> Destination: Sends message to Destination i.e. NATS / RabbitMQ / REST API
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.
The service can be configured using the following environment 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 |
Variable | Description |
---|---|
DESTINATION_TYPE | nats |
DESTINATION_URL | URL for the NATS destination |
PRODUCER_STREAM | Name of the stream for the NATS producer |
Variable | Description |
---|---|
DESTINATION_TYPE | rabbitmq |
DESTINATION_URL | URL for the RabbitMQ destination |
Queue | Name of the queue for the RabbitMQ producer |
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) |
Variable | Description |
---|---|
APM_ACTIVE | Enables Elastic APM |
APM_SERVICE | APM Service name |
APM_URL | APM server URL |
APM_SECRET_TOKEN | APM Secret token |
Variable | Description |
---|---|
LOGSTASH_LEVEL | Log level |
SIDECAR_HOST | Address that the event sidecar is listening on |
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.
git clone <repository-link>
Update the environment configuration file (.env) as per your system's requirements. Make sure to correctly configure any database or service connection details.
Once the environment is configured, build the Docker image using the following command:
docker compose build -t your-image-name
After building the image, start the service in detached mode (in the background) using the command:
docker compose up -d your-image-name
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:
- Calling the
startRelayServices()
function to initialize subscribers and begin message reading. - Processing incoming messages through the
execute()
function. - 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.
For any queries or assistance regarding the Relay service, you can reach out to the following contributors:
- Muhammad Umair Khan
GitHub ID: @UmairKhan-Paysys