Expand description
JetStream cellos_core::ports::EventSink — publishes JSON payloads to a configured subject.
§Reconnect / circuit-breaker model (P3-01)
JetStreamEventSink keeps a small in-memory state machine in front of the
underlying NATS connection so an extended broker outage cannot stall the
supervisor’s emit() path:
Connected— last publish succeeded. Nextemit()calls [Publisher::publish] directly (with a small bounded retry, seewith_retry).Reconnecting { attempt, next_after }— last publish failed.emit()returnsErrimmediately whileInstant::now() < next_after(the circuit is “open”). Oncenext_afterhas elapsed the sink takes one bounded probe attempt; on success the state resets toConnected, on failureattemptis incremented andnext_afteris pushed forward by an exponentially-backed-off interval.
The async-nats Client performs its own TCP-level reconnect under the
hood — this state machine is layered on top so that the supervisor’s
emit() returns Err quickly during an outage instead of being held by
the underlying client’s blocking publish path. Operators decide what to
do with that Err (typically log and continue).
Backoff schedule: 100ms * 2^attempt with attempt saturating at the
cap that keeps the value below 3 minutes (180s). So the sequence is
100ms, 200ms, 400ms, 800ms, 1.6s, 3.2s, …, 102.4s, 180s, 180s, ….
Backoff resets to attempt = 0 on the first successful publish after an
outage (acceptance: “Backoff resets on successful publish”).
Structs§
- JetStream
Event Sink - Publishes serialized
CloudEventV1to JetStream.
Constants§
- TENANT_
ID_ DEFAULT_ TOKEN - Sentinel value substituted for
{tenantId}when the event carries no tenant. - TENANT_
ID_ PLACEHOLDER - Subject template placeholder for the per-tenant isolation dimension (A2-03).
Functions§
- resolve_
tenant_ subject - Resolve a JetStream subject for
eventagainsttemplate. - with_
retry - Run
fup tomax_attemptstimes with exponential backoff on failure.