New Examples - NATS Cluster and 6PN Demo Chat

In our ongoing quest to show all the neat things you can do with Fly, here’s a peep at two new examples that go together. First, there’s a new NATS cluster example which leverages Fly’s 6PN .internal DNS to locate other servers in the cluster. And if you don’t have a NATS app to try that out with, we have 6PN-Demo-Chat, a web sockets based chat which relays messages through NATS for global reach. It also uses the 6PN DNS to locate the cluster. Enjoy and let us know how you get on!

1 Like

We are planning to use NATS for better log monitoring in flyctl down the road. It’s silly easy to install, and the way the subscriptions work makes it immediately responsive (you get messages from the nearest publishers very quickly) and easy to scale (if there’s no subscriber, publishing on a channel is basically a no-op).

For our purposes, this means running NATS nodes in each region and publishing log messages into app:<app-name> topics. When someone does flyctl logs, we will subscribe them to an app:<app-name> channel. That subscription gets gossiped around, so the regions that own an app’s VMs will start shipping messages over.

This is cleaner and simpler than what we’re currently doing, which is shipping all logs to a big ol’ Elasticsearch cluster, and then polling through our GraphQL API.

That sounds really clean, playing to strengths for both NATS and Fly. Is Fly hiring, btw? Projects like this ought to fun to work on.

We aren’t yet! We should be hiring for a developer experience role soon, we’ll post here when we do (and on Hacker News).

1 Like

Hi all, I’m having trouble finding instructions about how to use WireGurad with this example. I’m new to wireguard, and tunneling, networking …etc, so it’s likely user-error.

I followed the instructions here: Global NATS Cluster · Fly
But, when it gets to the WIreGuard instructions, it’s a bit unclear.

I want to connect to the cluster for local dev. From my laptop / application running locally.

I have a tunnel added to my machine, I followed the istructions here: Private Networking · Fly

I am able to query the DNS using the dig commands, but I can’t add a NATS context.

❯ nats context add --server my-app.internal:4222 --description "NATS cluster for my-app" --select 'my-app-context'
   Description: NATS cluster for my-app
      Server URLs: my-app.internal:4222
             Path: [redacted]
       Connection: dial tcp: i/o timeout

“dial tcp: i/o timeout”

What mm I doing wrong? Any help is appreciated.

Heya, this is interesting! NATS websockets seems like a good method of cross-communication between instances. Unfortunately, the nats-cluster example fails to deploy.

First deploy fails with critical errors. Likewise, adding regions fails. Authentication failure?

ord [info]nats-server | [557] [INF] Connecting to explicit gateway "cdg" (fly-local-6pn:7222) at [fdaa:0:4cc2:a7b:7d:c7bc:5829:2]:7222 (attempt 1)
ord [info]nats-server | [557] [INF] [fdaa:0:4cc2:a7b:7d:c7bc:5829:2]:7222 - gid:8 - Creating outbound gateway connection to "cdg"
ord [info]nats-server | [557] [INF] [fdaa:0:4cc2:a7b:7d:c7bc:5829:2]:48256 - gid:9 - Processing inbound gateway connection
ord [info]nats-server | [557] [ERR] [fdaa:0:4cc2:a7b:7d:c7bc:5829:2]:7222 - gid:8 - Failing connection to gateway "cdg", remote gateway name is "ord"
ord [info]nats-server | [557] [INF] [fdaa:0:4cc2:a7b:7d:c7bc:5829:2]:7222 - gid:8 - Gateway connection closed: Wrong Gateway
ord [info]nats-server | [557] [ERR] [fdaa:0:4cc2:a7b:7d:c7bc:5829:2]:48256 - gid:9 - authentication error
ord [info]nats-server | [557] [INF] [fdaa:0:4cc2:a7b:7d:c7bc:5829:2]:48256 - gid:9 - Gateway connection closed: Authentication Failure

Is this to be expected?

I noticed the errors on the logs when setting mine up without web sockets for instance communication. I modified the template so I could preload my operator and SYS account. You have to set the extra environment variables of course.

Now I need to figure out how to get it on the public internet. :slight_smile:

[edit]: got it though @kurt there is probably a better way to manage the security. I have to push accounts when changing the scale count.

1 Like

It would be good if this repo was updated. Many forks have happened because the main rep has fallen behind NATS. NATS did a huge updater 2 weeks ago.

Hello fellas
I have pickup an interest in having a NATS/jetstream pubsub server cluster for internal async tasks
So I’m here trying to start a cluster using this repo after having updated all dependencies (go, nats, exporter) versions and turns out nothing works!
All the machines hosting the NATS server are shutting down after a while, failing to find routes to other nodes
Also the prometheus exporter fork is just not working at all

So I started to get this back on track since I plan on using it extensively in the future

I’m planning on forking the repo and work my way from there but I wonder if that’s the smartest way to go

WDYT?