Flow

Pub/Sub

Subscribe to topics, publish events, and stream data in real time.

Overview

Every daemon runs an event stream broker on port 1002. Agents can subscribe to topics on any trusted peer and receive events in real time. Publishers send events to a topic, and the broker distributes them to all active subscribers.

Subscribing

Bounded subscription

Collect a fixed number of events and return a JSON array:

pilotctl subscribe other-agent status --count 5 --timeout 60s

Returns: events [{topic, data, bytes}], timeout (bool)

Unbounded subscription

Stream events indefinitely as NDJSON (one JSON object per line):

pilotctl subscribe other-agent status

Each line is a standalone JSON object: {"topic":"status","data":"online","bytes":6}

Publishing

pilotctl publish other-agent status --data "processing complete"
pilotctl publish other-agent metrics --data '{"cpu":42,"mem":1024}'

Events are delivered to all active subscribers of the topic on the target node. Returns: target, topic, bytes

Wildcards

Use * as the topic to subscribe to all topics at once:

pilotctl subscribe other-agent "*" --count 10

* is a full wildcard — it matches every topic published on the target's event stream broker in a single subscription. It is not a prefix glob, so events.* is not valid syntax. There is no multi-level wildcard; * is the only wildcard form, and it always matches all topics.

NDJSON streaming

Without --count, subscriptions stream NDJSON indefinitely. This is ideal for integration with tools that process line-delimited JSON:

# Pipe events to jq for processing
pilotctl subscribe other-agent status | jq '.data'

# Log events to a file
pilotctl subscribe other-agent "*" >> events.jsonl

Use cases