NGS Leaf Nodes
This mini-tutorial shows how to run 2 NATS server in local Docker containers interconnected via Synadia Cloud Platform. NGS is a global managed NATS network of NATS, and the local containers will connect to it as leaf nodes.
Start by creating a free account on https://cloud.synadia.com/.
Once you are logged in, go into the default
account (you can manage multiple isolated NGS account within your Synadia Cloud account).
In Settings
> Limits
, increase Leaf Nodes
to 2. Save the configuration change. (Your free account comes with up to 2 leaf connection, but the account is configured to use at most 1 initially).
Now navigate to the Users
section of your default
account and create 2 users, red
and blue
. (Users are another way you can isolate parts of your systems customizing permissions, access to data, limits and more)
For each of the two users, select Get Connected
and Download Credentials
.
You should now have 2 files on your computer: default-red.creds
and default-blue.creds
.
Create a minimal NATS Server configuration file leafnode.conf
, it will work for both leaf nodes:
Let's start the first leafnode (for user red
) with:
-p 4222:4222
maps the server port 4222 inside the container to your local port 4222. -v leafnode.conf:/leafnode.conf
mounts the configuration file created above at location /leafnode.conf
in the container. -v /etc/ssl/cert.pem:/etc/ssl/cert.pem
installs root certificates in the container, since the nats
image does not bundle them, and they are required to verify the TLS certificate presented by NGS. -v default-red.creds:/ngs.creds
installs the credentials for user red
at location /ngs.creds
inside the container. -c /leafnode.conf
are arguments passed to the container entry point (nats-server
).
Launching the container, you should see the NATS server starting successfully:
Now start the second leaf nodes with two minor tweaks to the command:
Notice we bind to local port 4333
(since 4222
) is busy, and we mount blue
credentials.
Congratulations, you have 2 leaf nodes connected to the NGS global network. Despite this being a global shared environment, your account is completely isolated from the rest of the traffic, and vice versa.
Now let's make 2 clients connected to the 2 leaf nodes talk to each other.
Let us start a simple service on the Leafnode of user red
:
Using the LeafNode run by user blue
, let's send a request:
Congratulations, you just connected 2 Leaf nodes to the global NGS network and used them to send a request and receive a response.
Your messages were routed transparently with millions of others, but they were not visible to anyone outside of your Synadia Cloud account.
Related and useful:
Official Docker image for the NATS server on GitHub and issues
Last updated