Back to Spy NATS
No TLS, Custom WebSocket Port
Same as the simplest setup, but the WebSocket port is moved off the default 8080.
TLS off (ws://)
No credentials
WS port 8777
nats-server.4-ok-ws-port.conf
1. Setup (nats-server.conf)
nats-server.conf
# Must expose the same websocket port in the docker run command
# (nats-server-start.sh) and in this config file, otherwise the browser
# viewer will fail with "Unable to connect to NATS over WebSocket at
# ws://<host>:<port>".
listen: 0.0.0.0:4222
http_port: 8222
# WebSocket transport — required for the browser to connect at all.
websocket {
port: 8777
no_tls: true
}
# JetStream — required for KV buckets and Streams.
jetstream {}
Docker port mapping (nats-server-start.sh)
docker run -d --restart unless-stopped \
-p 4222:4222 -p 8222:8222 -p 8777:8777 \
...One-time nats-cli setup
# nats-cli always talks to the core NATS port (4222), never the
# WebSocket port — the custom port above only matters to the browser viewer.
nats context add tutorial-custom-port \
--server="nats://10.135.32.227:4222" \
--selectIn Connection section, enter:
- NATS server host
- 10.135.32.227
- WS port
- 8777
- TLS (wss)
- off
- Username
- (leave blank)
- Password
- (leave blank)
2. Creation of subject / KV bucket / stream
Subject
In the Subscriptions form: Type: Subject · Target: orders.>
No setup required — just add the subscription above.
KV Bucket
In the Subscriptions form: Type: KV Bucket · Target: my-bucket
nats kv add my-bucketJetStream Stream
In the Subscriptions form: Type: JetStream Stream · Target: ORDERS · Filter: orders.created (optional)
nats stream add ORDERS --subjects "orders.>" --storage file \
--retention limits --max-msgs=-1 --max-bytes=-1 --max-age=0 --defaultsSystem Service
Not available
This configuration has no `accounts`/`system_account`, so $SYS.> system events are never published. See Tutorial 2 (No TLS, With Credentials) to enable system monitoring.
3. Message generation
Subject
nats pub orders.created '{"id": 1, "total": 42.5}'KV Bucket
nats kv put my-bucket hello worldJetStream Stream
nats pub orders.created '{"id": 1}'