The events plugin carries temporary messages and request/response exchanges between the callers of one open database.
Use it to tell a live consumer that facts changed, to wake a worker, or to exchange streaming results without writing a fact for each message.
Enable it at open with plugins {events {}}. It has no settings.
See plugin selection for the open options.
Events are not database state. A publication or an exchange message never enters the store, and commits never publish an event.
The plugin does not retry, acknowledge or replay a message.
Record anything that must survive as facts first, then publish an event that tells consumers to read those facts.
Only definitions of publication subjects and exchange routes are stored.
Events travel inside the process through the C API and the bindings; they use no network.
A caller opens an event owner with open_owner.
Subscriptions, worker registrations and exchange sides belong to the owner that created them.
Only that owner may use or end them; another owner's id reports wrong_owner.
close_owner ends everything the owner holds and cancels its exchanges: each other party reads a cancel notice.
Closing the database closes every owner and interrupts waiting calls with closed.
A publisher sends one native value to a literal subject with publish.
A subject is a non-empty, slash-separated name with no empty segment, such as orders/created.
Publishing needs no owner, and a publication with no matching subscriber succeeds.
An owner starts a subscription with subscribe.
Its pattern is a regular expression that Stardust anchors to the complete subject.
Thus orders/.* matches orders/created, while created does not.
The owner pulls events with receive, which waits up to maxWait.
A subscription queues at most 1024 events or 8 MB, and queued bytes count against the database memory budget.
When a queue is full, or the budget refuses a delivery, Stardust drops that delivery without delaying the publisher or other subscribers.
The publisher learns the number of deliveries and drops from the result of publish.
A subscription reports the deliveries it missed in the dropped member of the event it returns next.
A publication holds at most 1 MB of data.
unsubscribe ends a subscription and drops its queued events.
An exchange connects one caller to one worker. A worker registers a mode and a subject pattern with register.
A caller opens that mode on a literal subject with call. The registration with the lowest id among the matches serves the call, and a call with no matching worker reports no_worker.
Mode
Caller sends
Worker sends
request
One request, as data of the call
One response
push
A stream, then finish
One response, after the caller finished
pull
One request, as data of the call
A stream, then finish
duplex
A stream, then finish
A stream, then finish
The worker takes the next exchange with accept, which returns the worker side's handle and, for request and pull, the request.
Each side sends with send, tells the other party it sent everything with finish, and reads with read.
read returns a message, a finish or a cancel notice. Finishing closes only the finishing side's sending direction, so it can still read.
cancel ends the exchange at once, and the other party reads cancel.
Closing either owner cancels the exchange.
Unregistering a worker cancels its exchanges that are still waiting for acceptance.
Exchanges that the worker already accepted continue after unregistering.
Each side queues at most 1024 messages or 8 MB against the memory budget; a send that does not fit reports delivery_failed and cancels the exchange, because dropping a message would corrupt it.
A completed or cancelled exchange leaves its sides readable until their queues drain, then they disappear.
A stored definition of the event type fixes the request and response of a route.
Write it with patch_definition under the events kind at <mode>/<route>, for example request/orders/create.
Its document holds a JSON Schema for each direction:
The first path segment is the mode, which fixes who may stream. Use {} for a direction that carries any value.
A call with a definition checks its request, and every later message of the exchange against the schemas as they were when the call opened.
A message that breaks its schema reports invalid_payload and leaves the exchange running. A route without a definition is unchecked.
Definitions are ordinary stored definitions: history, backups and restores carry them.
A database that stores an event definition refuses to open without the events plugin, so its contracts cannot be skipped.
The SDK generation plugin renders typed publish, subscribe, caller and worker code for the stored routes in each language's output folder.
A publication definition lives at publish/<subject>, for example publish/orders/created.
Its document is the payload schema:
62 B
type object
required [order]
properties {order {type integer}}
Each publication uses the subject's current schema before it changes any subscriber queue.
Invalid data reports invalid_payload, including when there are no subscribers.
Subjects without definitions remain unchecked.
Generated publish and subscribe helpers bind the subject and payload type; subscriptions match the exact subject.
Event results preserve empty objects and arrays inside payloads.
options is not an object with owner and subscription (integers) and optionally a valid maxWait, or the subscription belongs to another owner (code wrong_owner)
options is not an object with owner and registration (integers) and optionally a valid maxWait, or the registration belongs to another owner (code wrong_owner)
request is malformed, the mode or subject is invalid (codes invalid_mode and invalid_subject), data is missing for request or pull, present for push or duplex, or exceeds 1 MB, or data does not match the stored request schema (code invalid_payload)
request is malformed, the side may not send now (code wrong_direction), the handle belongs to another owner (code wrong_owner), or data does not match its schema (code invalid_payload)