Topic rules
Every setting of a topic rule in the Console, from patterns and event types to access, presence and limits.
Topic rules decide which topics exist in a segment and what they carry. Manage them on the segment's Topic rules tab; owners and admins edit them. Rules are checked from the top, and the first match wins. A segment with no rules denies every topic. Topics explains the model.
Rule settings
| Setting | Default | Meaning |
|---|---|---|
| Pattern | required | Topic names it covers: * matches one level, a trailing > one or more. E.g. chat/*, rides/*/location |
| Who may use it | Anyone the token allows | Anyone the token allows makes matching topics public: the token decides. Members only makes them private: your backend keeps a member list |
| Event types | required | Which of Stream, KV and Signal the topics carry |
| Event names | none | Fix each event name to one type. With none, an event may have any name and any allowed type |
| Operations | all | The most any token may do on these topics: subscribe, publish, set, signal, history, presence |
| Presence | off | Subscribers show up in presence |
| Max payload | the segment's | A lower payload limit for these topics |
| Retention | 5 MiB | Stream history kept per topic, in bytes |
| TTL | 0 for KV, 5 s for signals | Default lifetime of values; 0 keeps a KV value until it is replaced |
| Max keys | 10,000 | KV values and signals kept per topic, together |
Event names
Listing event names is the safest setup: each name is held to its type, and a name you didn't list is refused. For each event you can set:
| Option | For | Meaning |
|---|---|---|
| Type | all | Stream, KV or Signal |
| TTL | KV, Signal | This event's default lifetime, overriding the rule's |
| Nobody can write another member's entry | KV | Only the publisher (or your backend) may write or delete its own key, e.g. a read receipt |
Examples
| Pattern | Types | Events | Access | For |
|---|---|---|---|---|
rooms/* | Stream, KV, Signal | message stream, read KV (own entry only), typing signal | Anyone the token allows | Chat rooms |
dm/* | Stream, KV, Signal | as above | Members only | Direct messages |
rides/*/location | KV | location KV, TTL 30 s | Anyone the token allows | Live map |
docs/* | KV, Signal | title KV, cursor signal | Anyone the token allows | Collaborative editing |
ai/* | Stream | token, done | Anyone the token allows | Streaming AI output |
Paste rules as JSON
Paste JSON takes rules in the same shape the Realtime API uses, which is also what the JavaScript SDK's
defineTopic(…).rule() produces:
[
{
"pattern": "rooms/*",
"types": ["stream", "kv", "signal"],
"events": {
"message": { "delivery": "stream" },
"read": { "delivery": "kv", "key_is_publisher": true },
"typing": { "delivery": "signal", "ttl_ms": 3000 }
},
"strict_events": true,
"access": "token",
"presence": true
}
]See Define topics and export rules.
Changing rules
Changes reach the Realtime API within seconds. Rules are matched in order, so put specific patterns, such as
rooms/announcements, above general ones like rooms/*.