LE NATS Pub Sub
6 min
Overview

Install
Prerequisites
- Litmus Edge 4.4.x
- A Litmus Edge user with access to Applications and to System -> Tokens
- The Litmus Edge NATS broker reachable from the container on port 4222
Steps
- After Checkout, download the file natspubsub-1-0-1.tar.gz from Litmus Central
- Log in to your Litmus Edge, navigate to Applications -> Images
- Click on Upload Image and upload the tar.gz file there
- Once uploaded successfully, navigate to System -> Tokens
- Either use an already created Rest API token, or
- Create a Rest API token and keep it handy
- Navigate back to Applications -> Containers and enter the following command there:
- docker run -e "NATS_HOST=<0.0.0.0>" -e "API_TOKEN=<token>" -e "SUB_TOPICS=<topic>" -e WINDOW_SIZE=5 -e "PUB_TOPICS=<result>" us-docker.pkg.dev/litmus-customer-facing/litmus-solutions/natspubsub/python:latest
- Use the API token as created from the previous step
- Here we are asking the container to subscribe to a specific topic, perform some calculations on it and publish to another topic, with the API token passed as an environment variable
- Window size is defined for performing the specific calculations
- The calculations done on the subscribed topic are:
- Mean of all values in the mentioned window
- Variance of all values in the mentioned window
- Standard Deviation of all values in the mentioned window
- The calculations are specific, and are meant to be used as an example template. Full customization of the calculation on the fly (e.g. changing it to some other calculation at runtime) is not yet supported
- Navigate to Flows Manager or Analytics to view the output on the topic <result>
Values
Variable | Default | Description |
|---|---|---|
NATS_HOST | 10.30.50.1 | Litmus Edge NATS broker host. Port 4222 is added automatically |
API_TOKEN | none, required | Token from System -> Tokens |
SUB_TOPICS | variable1, variable2, variable3, variable4 | Topic to subscribe to |
WINDOW_SIZE | 5 | Number of messages used for each calculation |
PUB_TOPICS | result | Topic the results are published to |
Check
- In Applications -> Containers, open the container log and confirm it prints Message published on topic once the window has filled
- In Analytics, confirm results appear on the PUB_TOPICS topic
Remove
- In Applications -> Containers, stop and remove the container
- In Applications -> Images, delete the image