go-nats-app

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2023 License: MIT

README

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL