← All lessons/Real-Time
41
Real-Time

Global Broadcast Bus & Publications

Subscribe to all events across all agents, and publish cross-agent messages.

Prerequisite: Lesson 40 complete

What you'll learn

  • GET /v1/stream — all events from all agents
  • Each event includes agent_id for client-side filtering
  • POST /v1/publications — broadcast to a topic
  • GET /v1/publications/subscribe?topic=... — topic subscription
  • Use case: one global dashboard for all agents
Challenge

Open global SSE stream. Write records to 3 different agents. Confirm global stream shows all 3 with their agent_id values.

What you'll learn

Subscribe to all events across all agents with the global SSE stream, and use named publications for durable multi-consumer change-feeds.

Global SSE stream

# All events from all agents
curl -N "http://localhost:7475/v1/stream" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY"

Filter by specific agents with ?agents=orders,users:

curl -N "http://localhost:7475/v1/stream?agents=orders,payments" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY"

Event format:

event: record.written
data: {
  "agent_id":     "orders",
  "event_type":   "record.written",
  "record_id":    "018f3c2a-...",
  "content_hash": "b3a7c2...",
  "timestamp_ms": 1754481600000,
  "flags":        0,
  "payload":      {"status": "paid"}
}

Publications — named durable change-feeds

The raw SSE stream is stateless. Publications add server-side cursor tracking so multiple independent consumers can each maintain their own position.

# 1. Create a publication covering the orders and payments agents
curl -s -X POST http://localhost:7475/v1/publications \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  -d '{"name": "order-feed", "agents": ["orders", "payments"]}' \
  | python3 -m json.tool

Save the returned id — you need it for the next steps.

# 2. Create a subscriber slot (tracks your cursor)
curl -s -X POST http://localhost:7475/v1/publications/<pub_id>/slots \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY" \
  -d '{"name": "analytics-consumer", "cursor_hlc": 0}' \
  | python3 -m json.tool
# 3. Open the durable SSE stream
curl -N "http://localhost:7475/v1/publications/<pub_id>/stream?slot=<slot_id>" \
  -H "Authorization: Bearer spx_root_YOUR_ROOT_KEY"

On reconnect, the stream automatically bacfkfills from your slot's last confirmed cursor — no events are missed.

Challenge

Create a publication covering two agents. Open two separate terminal streams using two different slots. Write records to both agents. Confirm each stream receives all events independently.

---

← Previous
Lesson 40: Per-Agent SSE Stream
Next →
Lesson 42: Durable Publications