I have read many articles and watched many tutorial videos, but the common ground for most of the material is to Publish changes to ALL users. Not Subscribing and get information what concerns just the user who is logged in.
The other common ground is Websockets protocol. There seems to be many other ways to skin this cat (Mark Twain) and I have some doubt which one to chose.
What I am searching for is a way for the user to login and connect to a server (Websocket server?) and say something like “Hey, I am Joe, please keep me updated on MY stuff”.
I have managed to set up a websocket server, but I only gets more confused how to proceed. How to think? The closest I have found is this and found also this. But this is above my pay grade. I do understand nothing.
In this stage I am mostly interested in “how to think”? No language specific.
Any input or direction is welcome!
Did you look into using existing messaging systems like NATS?
Never heard of it. What is the big difference comparing to Gorilla/Websocket?
Do I understand this correct that you can mimic “rooms” in Socket.io this way? ClientID = “room”?
sc, err := stan.Connect(clusterID, clientID, stan.NatsURL(url),
And how do I get “Joes stuff”? Send a query to Postgresql? Once or every 5 minutes?
We’re talking about different levels here. Websockets is a network communication protocol at the same protocol level as HTTP, whereas NATS is a message-passing system that runs on top of network protocols like TCP or Websockets.
I am not familiar with Socket.io and cannot tell you anything that’s not already in their docs. It seems that Socket.io does have some sort of broadcast mechanism using so-called rooms that allow sending messages to clients who joined that room. This sounds quite like what you are looking for—a solution to publish messages to subscribed clients.
Yes! I have read about NATS and it seems worth a try. And I can start the NATS-server on a Debian 10, but it seems that the server does not listen.
 2022/10/04 11:28:20.779634 [INF] Starting nats-server
 2022/10/04 11:28:20.779813 [INF] Version: 2.9.2
 2022/10/04 11:28:20.779846 [INF] Git: [6d81dde]
 2022/10/04 11:28:20.779883 [INF] Name: NDQU3V6PO7F63NIRX7AC65QZKB3DM73OIJADYBIO2JJMQOEE5HZSYE4Q
 2022/10/04 11:28:20.779911 [INF] ID: NDQU3V6PO7F63NIRX7AC65QZKB3DM73OIJADYBIO2JJMQOEE5HZSYE4Q
 2022/10/04 11:28:20.780183 [FTL] Error listening on port: 127.0.0.1:2222, "listen tcp 127.0.0.1:2222: bind: address already in use"
I found the executable nats-server-v2.9.2-linux-amd64 here I use this command to start the server:
./server --a 127.0.0.1 --port 2222
No Docker involved. Basically I followed roughly this instruction.
Any clue what I am doing wrong?
It seems that another process uses port 2222.
To troubleshoot this:
- Try another port
- Inspect the list of running processes to see if another server process is still running (from a previous launch maybe)
./server --help to see if the server has some flag for increasing the level of detail in the log output