Back to Spy NATS
Setup: WebSocket, Custom 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. NATS server setup
nats-server.conf
# Enable websocket on port 8777.
# Must expose the same websocket port in the docker run command
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 {
store_dir: "/data"
}
Run NATS server Docker with custom port mapping
docker run -d --name nats-server \
-p 4222:4222 -p 8222:8222 -p 8777:8777 \
-v $(pwd)/nats-server.conf:/etc/nats/nats-server.conf:ro \
nats:latest \
-c /etc/nats/nats-server.conf
One-time nats-cli connection 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. Subscription to 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. Messages creation
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}'