Publish
The Publish frame and POST /v1/publish, every field, receipts, idempotent retries, rate limits and errors.
Publishing is one frame, Publish, sent over a WebSocket or in the body of POST /v1/publish.
The Publish frame
| Field | Meaning |
|---|---|
topic or topic_id | Exactly one. Use the name the first time; the numeric topic_id comes back in the receipt |
name | The event name, e.g. message; 1–64 bytes |
delivery | The event type: Durable (stream), LastValue (kv) or Ephemeral (signal). Optional when the rule fixes the name's type, see event types |
payload | Your bytes, at most 60 KiB. Never parsed |
content_type | A label for receivers: Bytes, Json, Text, FlatBuffers, Protobuf, MsgPack, Cbor, or 1024 and up for your own. See content types |
headers | Up to 16 string pairs, passed through to subscribers |
idempotency_key | A 128-bit unique ID. Required for stream events; reuse it when retrying |
ack | Default, NoAck, Accepted or Committed. See below |
key | KV and signals: which value. Default: your identity |
ttl_ms | KV and signals: how long the value lives |
tombstone | KV: true deletes the key |
client_ts_ms | Your clock, passed through to subscribers |
Writing needs the op for the event's type in both the token and the rule: publish for stream events, set or
publish for KV, signal or publish for signals.
Receipts
On success the server answers PubAck:
| Field | Meaning |
|---|---|
topic_id | The topic's numeric ID |
epoch, seq | The event's cursor. seq is 0 for KV in a topic that carries several types |
uid | The event's permanent ID (stream and KV) |
duplicate | true when this was a retry of an event already accepted |
level | The level reached: Accepted |
server_ts_ms | When the server accepted it |
No PubAck is sent when you asked for NoAck, or for a signal left at Default (signals are fire-and-forget unless
you ask for Accepted). Failures always get OpError { code, message, retry_after_ms }.
Committed isn't offered: the receipt's level reports Accepted, meaning the event was accepted for delivery.
Retrying safely
Retry a stream publish with the same idempotency_key and the same content:
- within 10 minutes you get the original receipt with
duplicate: true, and it isn't delivered again; - the same key with different content gets
IdempotencyConflict; - keys are scoped to your identity and the topic.
Rate limits
A publish counts against your connection's rate, the topic's and the segment's. Over any of them you get
OpError { RateLimited, retry_after_ms } and nothing was published: send it again after the delay. When the
segment's outbound traffic is too high, the server slows publishers with Flow frames (see
flow control). A payload over the limit gets PayloadTooLarge. None of
these close the connection.
A publish refused for a monthly allowance gets QuotaExceeded with retry_after_ms set to the start of the next
period.
POST /v1/publish
Publishes without keeping a connection open.
POST https://realtime.folkways.net/v1/publish
Authorization: Bearer <token>
Content-Type: application/octet-stream
<one client packet: up to 64 Publish (and Ping) frames>| Body | One client packet of Publish frames, at most 64 KiB. No Hello: the header authenticates |
| Response | 200 with application/octet-stream: server packets, each prefixed by its length ([u32 LE length][packet]…). One PubAck or OpError per publish, matched by corr |
| Errors | Per-publish failures are OpError frames inside a 200. An authentication or packet-level failure returns the code's HTTP status and a body with one Close frame |
| CORS | Any origin; preflight allows POST with Authorization and Content-Type, cached 24 hours. No cookies |
Subscribe isn't accepted here (UnsupportedFrame); receive with POST /v1/poll or a
WebSocket.
Errors
| Code | When |
|---|---|
Forbidden | No rule matches the topic, or the token or rule doesn't allow the op. The same answer for both |
InvalidTopic | The name isn't a valid topic name |
ClassMismatch | The event type isn't allowed for this name or topic |
IdempotencyKeyRequired | A stream publish without an idempotency key |
IdempotencyConflict | The key was used with different content |
PayloadTooLarge | The payload is over the limit |
RateLimited | A rate limit was hit; retry after retry_after_ms |
QuotaExceeded | A monthly allowance or cap is used up, or the topic limit is reached |
All codes: Error codes.