Examples menu

NATS Visualizer multiplayer

Stop and restart four simulated services and watch what happens to their events. Auth and Inventory use Core pub/sub and lose events while stopped; Orders and Payments use JetStream and catch up. A KV heartbeat drives the health tiles.

OpenSwoole-native NATS client: a thin coroutine-native TCP client replaces third-party NATS libraries that require incompatible event loops. The read loop runs in a dedicated coroutine and yields cooperatively on every recv().
Core pub/sub (best-effort): Auth and Inventory subscribe via wildcard Core pub/sub (via.events.*). Fire-and-forget: if you kill one of these services its simulator stops and any events published while it is offline are gone forever.
Guaranteed delivery (JetStream durable consumers): Orders and Payments subscribe via named durable push consumers with explicit ACK. Kill = pause the consumer: the simulator keeps publishing, JetStream buffers un-ACKed messages. Revive = re-subscribe: the burst of missed events arrives immediately.
JetStream persistence: the VIAEVENTS stream captures every message in memory. The durable consumer tracks its last-delivered sequence across subscribe/unsubscribe cycles: a revived subscriber never misses a message.
KV health heartbeats: each service publishes a heartbeat to $KV.viahealth.{service} every 2 s. Guaranteed services always heartbeat (only the consumer is paused); best-effort services stop heartbeating when killed. The health grid reads KV age.
Lazy init: the NATS connection is established on the first page load inside the HTTP coroutine, where coroutine APIs are always safe. A double-init guard (flag set before Coroutine::create()) prevents race conditions.
One worker: this demo keeps the state of the services, the event log and the NATS connection in PHP statics, which each worker holds on its own. See What stays per worker before you run it with withWorkerNum().
NATS Connecting… 0 events logged
Services
ORD
Orders durable
waiting
0 events
PAY
Payments durable
waiting
0 events
AUTH
Auth best effort
waiting
0 events
INV
Inventory best effort
waiting
0 events
NATS
Core via.events.* auth, inventory
JetStream VIAEVENTS 0 msgs
Durable ui-orders, ui-payments ACK guaranteed
KV viahealth heartbeats
Audit via.events.* 0 logged
Health (KV age)
ORD Orders -
ORD DOWN
PAY Payments -
PAY DOWN
AUTH Auth -
AUTH DOWN
INV Inventory -
INV DOWN
Event Stream
Waiting for events…

Actions

kill-orders / kill-payments

Pauses the JetStream durable consumer (unsubscribes from the deliver inbox). Simulator keeps publishing; NATS buffers un-ACKed messages. Health tile stays green: the service is still alive, only the consumer is paused.

kill-auth / kill-inventory

Stops the event simulator entirely. Events are silently dropped: Core pub/sub has no persistence. Health tile flips to DOWN after 8 s of silence.

revive-{service} (×4)

Guaranteed services: re-subscribes to the deliver inbox; JetStream immediately delivers all buffered events in a burst. Best-effort: restarts the simulator and publishes a fresh KV heartbeat.

Views

mission_control.html.twig

Flow diagram from the services through NATS to the browser, service kill/revive cards with delivery-type badges, NATS topology with health tiles, and a live event stream.