go-nats-app

module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 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 spin-off, the nats client in the wasm connects using a CustomDialer again, but the connection is to a WebSocket Handler.

This handler adapts the websocket binary payloads to the standard Nats tcp connection Client Protocol.

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

This allows publishing the nats client endpoint as a websocket. The client nats connection and underlying websocket are managed as a go-app component.

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. Neat.

Disclaimers
  • Not fully tested, not production ready, no warranty, no support, etc.
  • The note here for writers of client libraries:
    • "Any data from a frame must be going through a parser that can handle partial protocols".
    • In this small demo, no issues were encountered. Maybe it is not applicable.
  • WebSocket Handler definitely needs to cover a few more error / connect / reconnect / disconnect cases.

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