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.

ModeCaller sendsWorker sends
requestOne request, as data of the callOne response
pushA stream, then finishOne response, after the caller finished
pullOne request, as data of the callA stream, then finish
duplexA stream, then finishA 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:

123 B
{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:

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.

Runtime status

Call status to inspect these fields:

FieldContents
ownersOpen owners
subscriptionsOpen subscriptions
registrationsWorker registrations
rpcsLive exchanges
queuedItems waiting in all queues

Operations

OperationReturnsSummary
Events::statusdocumentevents.status() returns the event runtime's owned status document.
Events::open_ownerdocumentevents.open_owner() opens an event owner and returns an owned document with its id.
Events::close_ownernoneevents.close_owner(owner) ends everything an owner holds and cancels its exchanges.
Events::publishdocumentevents.publish(event) delivers one temporary message to every matching subscription and returns an owned count document.
Events::subscribedocumentevents.subscribe(owner, pattern) starts a subscription of an owner and returns an owned document with its id.
Events::receivedocumentevents.receive(options) returns the oldest queued event of a subscription as an owned document.
Events::unsubscribenoneevents.unsubscribe(owner, subscription) ends a subscription and drops its queued events.
Events::registerdocumentevents.register(owner, mode, pattern) registers an owner as a worker for exchanges and returns an owned document with the registration id.
Events::unregisternoneevents.unregister(owner, registration) ends a worker registration.
Events::acceptdocumentevents.accept(options) takes the oldest waiting exchange of a registration and returns an owned document describing it.
Events::calldocumentevents.call(request) opens an exchange with the earliest matching worker and returns an owned document with the caller side's handle.
Events::sendnoneevents.send(request) sends one message on an exchange side to the other party.
Events::finishnoneevents.finish(owner, handle) ends the sending direction of an exchange side.
Events::cancelnoneevents.cancel(owner, handle) cancels an exchange and drops the caller's side.
Events::readdocumentevents.read(options) returns the oldest notice of an exchange side as an owned document.

Events::status

rust40 B
pub fn status(&self) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

The document counts owners, subscriptions, registrations, exchanges and queued items: see runtime status.

Examples

Count owners, subscriptions and queued items

rust35 B
let result = db.events().status()?;
TRON190 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 717565756564txt "queued"
0B02 00000000000000 00i64 0
140F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1EDC 72656769737472 6174696F6E73txt "registrations"
2C02 00000000000000 00i64 0
350F 0A 1E000000 2C00 0000map leaf, size 10: @1E → @2C
3F4C 72706373txt "rpcs"
4402 00000000000000 00i64 0
4D0F 0A 3F000000 4400 0000map leaf, size 10: @3F → @44
5707 0E 88000000 3500 0000 4D000000map branch, size 14, depth 1, slots 3, 7: @35 → @4D
656C 6F776E657273txt "owners"
6C02 00000000000000 00i64 0
750F 0A 65000000 6C00 0000map leaf, size 10: @65 → @6C
7FDC 73756273637269 7074696F6E73txt "subscriptions"
8D02 00000000000000 00i64 0
960F 0A 7F000000 8D00 0000map leaf, size 10: @7F → @8D
A007 16 101A0000 1400 0000 57000000 7500 0000 96000000map branch, size 22, depth 0 (root), slots 4, 9, 11, 12: @14 → @57 → @75 → @96

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::open_owner

rust44 B
pub fn open_owner(&self) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.

Errors

StatusWhen
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

Subscriptions, registrations and exchange sides belong to an owner. See owners.

Examples

Open an event owner

rust39 B
let result = db.events().open_owner()?;
TRON37 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 6F776E6572txt "owner"
0A02 01000000000000 00i64 1
130F 0A 04000000 0A00 0000map leaf, size 10: @4 → @A

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::close_owner

rust51 B
pub fn close_owner(&self, owner: i64) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
owneri64ValueRequiredThe owner that opened it, from open_owner.

Errors

StatusWhen
Status::INVALID_ARGUMENTthe request is not an object with only an integer owner
Status::NOT_FOUNDthe owner does not exist or ended
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed

Examples

Close an owner and everything it holds

rust55 B
db.events().open_owner()?;
db.events().close_owner(1)?;

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::publish

rust59 B
pub fn publish(&self, event: &Document) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
event&DocumentBorrowed for the callRequiredA borrowed object {subject data}. subject is a literal subject; data is any native value.

Errors

StatusWhen
Status::INVALID_ARGUMENTevent is not an object with exactly subject and data, the subject is malformed (code invalid_subject), or data exceeds 1 MB (code too_large)
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

A publication is never stored or replayed. See publishing.

Examples

Publish a temporary message

rust195 B
db.events().open_owner()?;
db.events().subscribe(1, "orders/.*")?;
let doc3 = stardust::parse("{subject orders/created data {order 42}}", Format::DUST)?;
let result = db.events().publish(&doc3)?;
TRON82 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
049C 64656C69766572 6564txt "delivered"
0E02 01000000000000 00i64 1
170F 0A 04000000 0E00 0000map leaf, size 10: @4 → @E
217C 64726F70706564txt "dropped"
2902 00000000000000 00i64 0
320F 0A 21000000 2900 0000map leaf, size 10: @21 → @29
3C07 0E 02040000 1700 0000 32000000map branch, size 14, depth 0 (root), slots 1, 10: @17 → @32

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::subscribe

rust70 B
pub fn subscribe(&self, owner: i64, pattern: &str) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
owneri64ValueRequiredThe owner that opened it, from open_owner.
pattern&strValueRequiredA regular expression for the complete subject.

Errors

StatusWhen
Status::INVALID_ARGUMENTthe request is malformed, or the pattern is empty or not a valid regular expression (code invalid_pattern)
Status::NOT_FOUNDthe owner does not exist
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

A pattern is a regular expression anchored to the complete subject. See subscriptions.

Examples

Subscribe to every order subject

rust79 B
db.events().open_owner()?;
let result = db.events().subscribe(1, "orders/.*")?;
TRON44 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04CC 73756273637269 7074696F6Etxt "subscription"
1102 02000000000000 00i64 2
1A0F 0A 04000000 1100 0000map leaf, size 10: @4 → @11

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::receive

rust61 B
pub fn receive(&self, options: &Document) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
options&DocumentBorrowed for the callRequired options record. See field defaultsA borrowed object {owner subscription maxWait}. maxWait is an optional nonnegative native duration.

Errors

StatusWhen
Status::INVALID_ARGUMENToptions is not an object with owner and subscription (integers) and optionally a valid maxWait, or the subscription belongs to another owner (code wrong_owner)
Status::NOT_FOUNDthe owner or the subscription does not exist
Status::TIMEOUTmaxWait passed before an event arrived
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

receive waits up to maxWait. Without it the call checks once and reports timeout when no event is queued.

Examples

Receive the oldest queued event

rust315 B
db.events().open_owner()?;
db.events().subscribe(1, "orders/.*")?;
let doc3 = stardust::parse("{subject orders/created data {order 42}}", Format::DUST)?;
db.events().publish(&doc3)?;
let doc4 = stardust::parse("{owner 1 subscription 2 maxWait {#dur PT1S}}", Format::DUST)?;
let result = db.events().receive(&doc4)?;
TRON172 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
045C 6F72646572txt "order"
0A02 2A000000000000 00i64 42
130F 0A 04000000 0A00 0000map leaf, size 10: @4 → @A
1D4C 64617461txt "data"
220F 0A 1D000000 1300 0000map leaf, size 10: @1D → @13
2C7C 7375626A656374txt "subject"
34EC 6F72646572732F 63726561746564txt "orders/created"
430F 0A 2C000000 3400 0000map leaf, size 10: @2C → @34
4D7C 64726F70706564txt "dropped"
5502 00000000000000 00i64 0
5E0F 0A 4D000000 5500 0000map leaf, size 10: @4D → @55
6807 0E 09000000 4300 0000 5E000000map branch, size 14, depth 1, slots 0, 3: @43 → @5E
768C 73657175656E63 65txt "sequence"
7F02 01000000000000 00i64 1
880F 0A 76000000 7F00 0000map leaf, size 10: @76 → @7F
9207 12 20240000 2200 0000 68000000 8800 0000map branch, size 18, depth 0 (root), slots 5, 10, 13: @22 → @68 → @88

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::unsubscribe

rust70 B
pub fn unsubscribe(&self, owner: i64, subscription: i64) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
owneri64ValueRequiredThe owner that opened it, from open_owner.
subscriptioni64ValueRequiredThe id subscribe returned.

Errors

StatusWhen
Status::INVALID_ARGUMENTthe request is malformed, or the subscription belongs to another owner (code wrong_owner)
Status::NOT_FOUNDthe owner or the subscription does not exist or ended
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed

Examples

End a subscription

rust98 B
db.events().open_owner()?;
db.events().subscribe(1, "orders/.*")?;
db.events().unsubscribe(1, 2)?;

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::register

rust81 B
pub fn register(&self, owner: i64, mode: &str, pattern: &str) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
owneri64ValueRequiredThe owner that opened it, from open_owner.
mode&strValueRequiredrequest, push, pull or duplex.
pattern&strValueRequiredA regular expression for the complete subject.

Errors

StatusWhen
Status::INVALID_ARGUMENTthe request is malformed, the mode is unknown (code invalid_mode) or the pattern is empty or invalid (code invalid_pattern)
Status::NOT_FOUNDthe owner does not exist
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

The earliest matching registration serves each call. See exchanges.

Examples

Register an owner as a worker

rust89 B
db.events().open_owner()?;
let result = db.events().register(1, "request", "orders/.*")?;
TRON44 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
04CC 72656769737472 6174696F6Etxt "registration"
1102 02000000000000 00i64 2
1A0F 0A 04000000 1100 0000map leaf, size 10: @4 → @11

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::unregister

rust69 B
pub fn unregister(&self, owner: i64, registration: i64) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
owneri64ValueRequiredThe owner that opened it, from open_owner.
registrationi64ValueRequiredThe id register returned.

Errors

StatusWhen
Status::INVALID_ARGUMENTthe request is malformed, or the registration belongs to another owner (code wrong_owner)
Status::NOT_FOUNDthe owner or the registration does not exist
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed

Examples

End a worker registration

rust107 B
db.events().open_owner()?;
db.events().register(1, "request", "orders/.*")?;
db.events().unregister(1, 2)?;

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::accept

rust60 B
pub fn accept(&self, options: &Document) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
options&DocumentBorrowed for the callRequired options record. See field defaultsA borrowed object {owner registration maxWait}. maxWait is an optional nonnegative native duration.

Errors

StatusWhen
Status::INVALID_ARGUMENToptions is not an object with owner and registration (integers) and optionally a valid maxWait, or the registration belongs to another owner (code wrong_owner)
Status::NOT_FOUNDthe owner or the registration does not exist
Status::TIMEOUTmaxWait passed before an exchange arrived
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

accept waits up to maxWait. The result carries the worker side's handle: see exchanges.

Examples

Take the oldest waiting exchange as the worker

rust372 B
db.events().open_owner()?;
db.events().open_owner()?;
db.events().register(2, "request", "orders/.*")?;
let doc4 = stardust::parse("{owner 1 mode request subject orders/create data {customer Ada}}", Format::DUST)?;
db.events().call(&doc4)?;
let doc5 = stardust::parse("{owner 2 registration 3 maxWait {#dur PT1S}}", Format::DUST)?;
let result = db.events().accept(&doc5)?;
TRON180 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 637573746F6D65 72txt "customer"
0D3C 416461txt "Ada"
110F 0A 04000000 0D00 0000map leaf, size 10: @4 → @D
1B4C 64617461txt "data"
200F 0A 1B000000 1100 0000map leaf, size 10: @1B → @11
2A4C 6D6F6465txt "mode"
2F7C 72657175657374txt "request"
370F 0A 2A000000 2F00 0000map leaf, size 10: @2A → @2F
416C 68616E646C65txt "handle"
4802 06000000000000 00i64 6
510F 0A 41000000 4800 0000map leaf, size 10: @41 → @48
5B7C 7375626A656374txt "subject"
63DC 6F72646572732F 637265617465txt "orders/create"
710F 0A 5B000000 6300 0000map leaf, size 10: @5B → @63
7B3C 727063txt "rpc"
7F02 04000000000000 00i64 4
880F 0A 7B000000 7F00 0000map leaf, size 10: @7B → @7F
9207 1A 60260000 2000 0000 37000000 5100 0000 71000000 8800 0000map branch, size 26, depth 0 (root), slots 5, 6, 9, 10, 13: @20 → @37 → @51 → @71 → @88

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::call

rust58 B
pub fn call(&self, request: &Document) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
request&DocumentBorrowed for the callRequiredA borrowed object {owner mode subject data}.

Errors

StatusWhen
Status::INVALID_ARGUMENTrequest 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)
Status::NOT_FOUNDthe owner does not exist, or no registered worker matches (code no_worker)
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

A stored definition for the route checks every message. See exchanges and definitions.

Examples

Open a request exchange with a worker

rust253 B
db.events().open_owner()?;
db.events().open_owner()?;
db.events().register(2, "request", "orders/.*")?;
let doc4 = stardust::parse("{owner 1 mode request subject orders/create data {customer Ada}}", Format::DUST)?;
let result = db.events().call(&doc4)?;
TRON75 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
046C 68616E646C65txt "handle"
0B02 05000000000000 00i64 5
140F 0A 04000000 0B00 0000map leaf, size 10: @4 → @B
1E3C 727063txt "rpc"
2202 04000000000000 00i64 4
2B0F 0A 1E000000 2200 0000map leaf, size 10: @1E → @22
3507 0E 00220000 1400 0000 2B000000map branch, size 14, depth 0 (root), slots 9, 13: @14 → @2B

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::send

rust52 B
pub fn send(&self, request: &Document) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
request&DocumentBorrowed for the callRequiredA borrowed object {owner handle data}.

Errors

StatusWhen
Status::INVALID_ARGUMENTrequest 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)
Status::NOT_FOUNDthe owner or the side does not exist, or the exchange ended and the side drained
Status::CONFLICTthe side already finished (code already_finished), or the other party's queue is full (code delivery_failed)
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed

Notes

A message is checked against the stored schemas of its route. See exchanges.

Examples

Answer a request as the worker

rust451 B
db.events().open_owner()?;
db.events().open_owner()?;
db.events().register(2, "request", "orders/.*")?;
let doc4 = stardust::parse("{owner 1 mode request subject orders/create data {customer Ada}}", Format::DUST)?;
db.events().call(&doc4)?;
let doc5 = stardust::parse("{owner 2 registration 3}", Format::DUST)?;
db.events().accept(&doc5)?;
let doc6 = stardust::parse("{owner 2 handle 6 data {accepted true}}", Format::DUST)?;
db.events().send(&doc6)?;

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::finish

rust59 B
pub fn finish(&self, owner: i64, handle: i64) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
owneri64ValueRequiredThe owner that opened it, from open_owner.
handlei64ValueRequiredThe side handle: from call for the caller, from accept for the worker.

Errors

StatusWhen
Status::INVALID_ARGUMENTthe request is malformed, the side cannot finish in this mode (code wrong_direction), or the handle belongs to another owner (code wrong_owner)
Status::NOT_FOUNDthe owner or the side does not exist
Status::CONFLICTthe side already finished (code already_finished), or the other party's queue is full (code delivery_failed)
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed

Examples

Finish the caller's stream

rust238 B
db.events().open_owner()?;
db.events().open_owner()?;
db.events().register(2, "push", "uploads/.*")?;
let doc4 = stardust::parse("{owner 1 mode push subject uploads/a}", Format::DUST)?;
db.events().call(&doc4)?;
db.events().finish(1, 5)?;

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::cancel

rust59 B
pub fn cancel(&self, owner: i64, handle: i64) -> Result<()>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
owneri64ValueRequiredThe owner that opened it, from open_owner.
handlei64ValueRequiredThe side handle: from call for the caller, from accept for the worker.

Errors

StatusWhen
Status::INVALID_ARGUMENTthe request is malformed, or the handle belongs to another owner (code wrong_owner)
Status::NOT_FOUNDthe owner or the side does not exist
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed

Examples

Cancel an exchange

rust238 B
db.events().open_owner()?;
db.events().open_owner()?;
db.events().register(2, "push", "uploads/.*")?;
let doc4 = stardust::parse("{owner 1 mode push subject uploads/a}", Format::DUST)?;
db.events().call(&doc4)?;
db.events().cancel(1, 5)?;

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release

Events::read

rust58 B
pub fn read(&self, options: &Document) -> Result<Document>

Parameters

ParameterTypeOwnershipDefaultMeaning
self&SelfBorrowed for the callRequiredThe events owner for this operation. Keep it alive during the call.
options&DocumentBorrowed for the callRequired options record. See field defaultsA borrowed object {owner handle maxWait}. maxWait is an optional nonnegative native duration.

Errors

StatusWhen
Status::INVALID_ARGUMENToptions is not an object with owner and handle (integers) and optionally a valid maxWait, or the handle belongs to another owner (code wrong_owner)
Status::NOT_FOUNDthe owner or the side does not exist, or it drained after the exchange ended
Status::TIMEOUTmaxWait passed before a notice arrived
Status::UNAVAILABLEthe database does not enable the events plugin
Status::CLOSEDthe database is closed
Status::OUT_OF_MEMORYnative memory is exhausted

Notes

A message, the other party's finish or a cancel arrives as kind message, finish or cancel.

Examples

Read the worker's response

rust575 B
db.events().open_owner()?;
db.events().open_owner()?;
db.events().register(2, "request", "orders/.*")?;
let doc4 = stardust::parse("{owner 1 mode request subject orders/create data {customer Ada}}", Format::DUST)?;
db.events().call(&doc4)?;
let doc5 = stardust::parse("{owner 2 registration 3}", Format::DUST)?;
db.events().accept(&doc5)?;
let doc6 = stardust::parse("{owner 2 handle 6 data {accepted true}}", Format::DUST)?;
db.events().send(&doc6)?;
let doc7 = stardust::parse("{owner 1 handle 5 maxWait {#dur PT1S}}", Format::DUST)?;
let result = db.events().read(&doc7)?;
TRON94 B
Offset (hex)Bytes (hex)Meaning
0054 52 4F 4Emagic TRON
048C 61636365707465 64txt "accepted"
0D09bit true
0E0F 0A 04000000 0D00 0000map leaf, size 10: @4 → @D
184C 6B696E64txt "kind"
1D7C 6D657373616765txt "message"
250F 0A 18000000 1D00 0000map leaf, size 10: @18 → @1D
2F4C 64617461txt "data"
340F 0A 2F000000 0E00 0000map leaf, size 10: @2F → @E
3E07 0E 0C000000 2500 0000 34000000map branch, size 14, depth 1, slots 2, 3: @25 → @34
4C07 0A 20000000 3E00 0000map branch, size 10, depth 0 (root), slots 5: @3E

C exports: stardust_db_plugin_call, stardust_result_take_document, stardust_result_error, stardust_result_release