Skip to content

mlctrez/go-nats-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-nats-app

A spin-off of go-nats-app. See the readme there for full details.

Credit to Hans for the original and sending me on this journey.

Most of the original code is in setupNatsApi for the server and front.go for the client. Nats server setup is in service.go.

Changes in this spin-off

In the original code, the nats client in the wasm connects to the nats server using a Nats Websocket via a CustomDialer.

Go-App -> Nats Client -> <Nats WebSocket> -> WebSocket Endpoint

In the (now updated) spin-off, the nats client in the wasm connects using goapp-natsws.

Go-App -> Nats Client -> <natsws.Connection> -> <natsws.Proxy> -> WebSocket Endpoint

This allows the nats communication to be on the same host:port where the go-app is served.

Incrementing the echo counter in the original was replaced with a client http get to /echo/username.

Interestingly, this led to the discovery of the nats client connection option nats.InProcessServer.

A disconnect test was added to simulate the backend disconnecting the websocket.

Disclaimers

  • See readme in goapp-natsws
  • As pointed out, this seems like a bit like re-inventing the wheel.
    • This is not intended to replace the built-in nats websocket client with all of its fail over / cluster capabilities.
    • Use the default nats client if that's needed.

Go Report Card

created by tigwen

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published