pub struct BusClient { /* private fields */ }Expand description
A module’s current connection and the task that maintains its credentials.
Implementations§
Source§impl BusClient
impl BusClient
Sourcepub async fn connect(
subc: Arc<SubcConsumer>,
opts: BusClientOptions,
) -> Result<Self>
pub async fn connect( subc: Arc<SubcConsumer>, opts: BusClientOptions, ) -> Result<Self>
Issues a credential for the module identity that the subc daemon authenticates from the module’s launch nonce.
Sourcepub fn connection(&self) -> NatsConnection
pub fn connection(&self) -> NatsConnection
Returns a snapshot. A re-issue does not change an already held snapshot.
Sourcepub fn connection_changes(&self) -> Receiver<u64>
pub fn connection_changes(&self) -> Receiver<u64>
Changes only after a replacement connection with its issued inbox prefix is ready.
Reopen raw subscriptions and durable pulls when this receiver changes;
EventReader handles its own rebinding automatically.
If credential maintenance can no longer renew or re-issue, its task ends
and drops the sender. The receiver’s changed() then returns Err once
any unseen change has been consumed. Reconnect with BusClient::connect
or report the module as degraded when the change stream closes.
pub fn acct(&self) -> &str
Sourcepub fn box_id(&self) -> Option<BoxId>
pub fn box_id(&self) -> Option<BoxId>
Returns the computer’s box id as supplied by the bus module’s account.
Modules must never derive this id themselves. Returns None unless the
account is box_ followed by a canonical 32-character box id.
Sourcepub fn inbox_prefix(&self) -> String
pub fn inbox_prefix(&self) -> String
Returns the inbox prefix used by the current connection.
A per-credential prefix changes after credential re-issue; a module’s
ckdel prefix stays stable. Use Self::connection_changes to observe
replacements, or NatsConnection::inbox_prefix for a held snapshot.
Sourcepub async fn event_reader(&self, durable: &str) -> Result<EventReader>
pub async fn event_reader(&self, durable: &str) -> Result<EventReader>
Attaches to an existing EVENT durable owned by this module.
ck-bus provisions durables; this method never creates or changes one.
The name must follow bus-naming’s m_{module}[_suffix] owner rule.
The reader rebinds automatically after credential re-issue. Nothing is
acknowledged automatically: commit your own transaction before ack().
Sourcepub fn bucket(&self, owner_module: &str, bucket: &str) -> Result<Bucket>
pub fn bucket(&self, owner_module: &str, bucket: &str) -> Result<Bucket>
Opens a declared module bucket for its owner or a declared reader. Does not provision buckets or change their limits.
Sourcepub async fn publish_event(
&self,
event: &str,
version: u32,
qualifier: Option<&str>,
msg_id: &str,
body: impl Into<Bytes>,
) -> Result<PublishReceipt>
pub async fn publish_event( &self, event: &str, version: u32, qualifier: Option<&str>, msg_id: &str, body: impl Into<Bytes>, ) -> Result<PublishReceipt>
Stores an event using the fact’s own id for JetStream deduplication.
Event bodies carry ids, counters and enums, not large content. Bodies
larger than 4 KiB are refused; retrieve large content through its owner’s
own call instead.
A non-empty body is sent with its SHA-256 as Ck-Content-Digest, so a
reader can check the bytes it received. An empty body is sent without one,
because an empty payload with a digest is the claim-check shape.
Inline bodies reach every reader whose durable matches the subject, with
no per-reader visibility check; reserve them for pointers and facts every
declared reader may see. Flow triggers must use Self::publish_claim_check,
the cortexkit_bus_trait::Stream::publish claim-check path (empty payload plus
content digest), with the publisher serving the body under the reading
flow’s own scope to check which agent may see it. The flow engine refuses
inline trigger bodies.
Sourcepub async fn publish_claim_check(
&self,
event: &str,
version: u32,
qualifier: Option<&str>,
msg_id: &str,
digest: ContentDigest,
headers: Headers,
) -> Result<PublishReceipt>
pub async fn publish_claim_check( &self, event: &str, version: u32, qualifier: Option<&str>, msg_id: &str, digest: ContentDigest, headers: Headers, ) -> Result<PublishReceipt>
Publishes an empty-payload claim check carrying the body’s content digest.
Store the body before publishing and serve it through the publisher’s own
events_get query under the reading flow’s scope. This is the event shape
for triggering flows; inline bodies cannot be used as flow triggers.
The NATS codec writes Nats-Msg-Id and Ck-Content-Digest and refuses caller
headers spelling either reserved name, including case variants.