Events
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.
Follow Checkers with the events plugin for a runnable progression through pub/sub, request, pull, push and duplex.
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.
Owners
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.
Publish and subscribe
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.
Exchanges
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.
Definitions
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:
{request {type object required [customer] properties {customer {type string}}}
response {type object required [accepted]}}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:
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.
Runtime status
Call status to inspect these fields:
| Field | Contents |
|---|---|
owners | Open owners |
subscriptions | Open subscriptions |
registrations | Worker registrations |
rpcs | Live exchanges |
queued | Items waiting in all queues |
Operations
| Operation | Returns | Summary |
|---|---|---|
| status | Unavailable | events.status() returns the event runtime's owned status document. |
| open_owner | Unavailable | events.open_owner() opens an event owner and returns an owned document with its id. |
| close_owner | Unavailable | events.close_owner(owner) ends everything an owner holds and cancels its exchanges. |
| publish | Unavailable | events.publish(event) delivers one temporary message to every matching subscription and returns an owned count document. |
| subscribe | Unavailable | events.subscribe(owner, pattern) starts a subscription of an owner and returns an owned document with its id. |
| receive | Unavailable | events.receive(options) returns the oldest queued event of a subscription as an owned document. |
| unsubscribe | Unavailable | events.unsubscribe(owner, subscription) ends a subscription and drops its queued events. |
| register | Unavailable | events.register(owner, mode, pattern) registers an owner as a worker for exchanges and returns an owned document with the registration id. |
| unregister | Unavailable | events.unregister(owner, registration) ends a worker registration. |
| accept | Unavailable | events.accept(options) takes the oldest waiting exchange of a registration and returns an owned document describing it. |
| call | Unavailable | events.call(request) opens an exchange with the earliest matching worker and returns an owned document with the caller side's handle. |
| send | Unavailable | events.send(request) sends one message on an exchange side to the other party. |
| finish | Unavailable | events.finish(owner, handle) ends the sending direction of an exchange side. |
| cancel | Unavailable | events.cancel(owner, handle) cancels an exchange and drops the caller's side. |
| read | Unavailable | events.read(options) returns the oldest notice of an exchange side as an owned document. |
status
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
open_owner
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
close_owner
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
publish
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
subscribe
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
receive
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
unsubscribe
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
register
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
unregister
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
accept
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
call
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
send
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
finish
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
cancel
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release
read
C calls plugin operations through stardust_db_plugin_call and stardust_db_plugin_stream_open with a request document.
Also calls: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release