Skip to main content

Crate nenjo_eventbus

Crate nenjo_eventbus 

Source
Expand description

§nenjo-eventbus

Transport-agnostic event bus for the Nenjo agent platform.

This crate provides EventBus, a raw envelope transport for sending and receiving agent events. The underlying transport is pluggable via the Transport trait — enable the nats feature for a production-ready NATS JetStream implementation. For high-throughput workers, clone an EventBusPublisher from the bus and run outbound publishes separately from the inbound receive loop.

§Quick start (NATS)

use nenjo_eventbus::{EventBus, EventBusBuilder, Subscription};
use nenjo_eventbus::nats::NatsTransport;
use nenjo_events::Envelope;

let transport = NatsTransport::builder()
    .urls(vec!["nats://localhost:4222".to_string()])
    .token("my-api-key")
    .build()
    .await?;

let bus = EventBus::builder()
    .transport(transport)
    .subscription(Subscription::worker_commands(worker_id, capabilities))
    .build()
    .await?;

// Send a raw envelope directly, or clone bus.publisher() for an outbound lane.
let envelope = Envelope::new(user_id, serde_json::json!({ "type": "ping" }));
bus.send_envelope("requests.chat", &envelope).await?;

// Receive envelopes
while let Some(received) = bus.recv_envelope().await? {
    println!("{:?}", received.envelope);
    received.ack().await?;
}

Structs§

Envelope
Wire envelope wrapping every event on the message bus.
EventBus
Raw event bus for sending and receiving transport envelopes.
EventBusBuilder
Builder for constructing an EventBus.
EventBusPublisher
Cloneable outbound handle for publishing raw envelopes.
Message
A message received from the transport layer.
MessageSource
NoOpAck
No-op ack handle for transports that don’t require acknowledgment.
ReceivedEnvelope
A raw envelope received from the bus, paired with its ack handle.

Enums§

EventBusError
Errors returned by event bus operations.
Subscription

Traits§

AckHandle
Handle for acknowledging a message back to the transport.
Transport
The transport layer abstraction.