Skip to main content

K2KBroker

Struct K2KBroker 

Source
pub struct K2KBroker { /* private fields */ }
Expand description

K2K message broker with per-tenant isolation.

Internally holds a HashMap<TenantId, K2KSubBroker>. Single-tenant deployments see exactly one entry (for UNSPECIFIED_TENANT = 0); the only overhead over the legacy broker is one additional HashMap lookup per send (~20 ns).

Implementations§

Source§

impl K2KBroker

Source

pub fn new(config: K2KConfig) -> Arc<Self>

Create a new K2K broker with an empty TenantRegistry.

Source

pub fn with_registry( config: K2KConfig, registry: Arc<TenantRegistry>, ) -> Arc<Self>

Create a new K2K broker sharing the given TenantRegistry.

This is the multi-tenant constructor: wire up the registry (with its audit sink) once, then pass the Arc to every broker that should enforce against it.

Source

pub fn registry(&self) -> &Arc<TenantRegistry>

Shared reference to the tenant registry.

Source

pub fn tenant_count(&self) -> usize

Total number of active tenant sub-brokers.

Source

pub fn sub_broker(&self, tenant_id: TenantId) -> Option<Arc<K2KSubBroker>>

Get the sub-broker for a tenant, if it exists.

Source

pub fn register(self: &Arc<Self>, kernel_id: KernelId) -> K2KEndpoint

Register a kernel without a tenant / audit tag (legacy API).

The kernel is placed in the unspecified-tenant sub-broker (UNSPECIFIED_TENANT = 0). This is the backward-compatible entry point for single-tenant deployments — existing callers don’t need to change anything.

Source

pub fn register_tenant( self: &Arc<Self>, tenant_id: TenantId, audit_tag: AuditTag, kernel_id: KernelId, ) -> K2KEndpoint

Register a kernel into the given tenant’s sub-broker, stamping the AuditTag that will be applied to outgoing messages from this kernel.

If the tenant doesn’t yet have a sub-broker, one is created lazily. If the kernel was previously registered under a different tenant, the old registration is replaced (the old mpsc sender is dropped — in-flight messages to the old registration are lost). This preserves the invariant that a kernel belongs to exactly one tenant.

Source

pub fn unregister(&self, kernel_id: &KernelId)

Unregister a kernel from whichever tenant it belongs to.

Source

pub fn is_registered(&self, kernel_id: &KernelId) -> bool

Check if a kernel is registered (under any tenant).

Source

pub fn tenant_of(&self, kernel_id: &KernelId) -> Option<TenantId>

Get the tenant this kernel belongs to, if registered.

Source

pub fn registered_kernels(&self) -> Vec<KernelId>

All registered kernel IDs (across every tenant).

Source

pub fn registered_kernels_for(&self, tenant_id: TenantId) -> Vec<KernelId>

Kernel IDs registered under a specific tenant.

Source

pub async fn send( &self, source: KernelId, destination: KernelId, envelope: MessageEnvelope, ) -> Result<DeliveryReceipt>

Send a message from one kernel to another (normal priority).

Enforces tenant isolation: the sender’s and destination’s tenants must match, or the send is rejected with crate::error::RingKernelError::TenantMismatch and an audit event is emitted.

Source

pub async fn send_priority( &self, source: KernelId, destination: KernelId, envelope: MessageEnvelope, priority: u8, ) -> Result<DeliveryReceipt>

Send a priority message.

Source

pub async fn send_with_audit( &self, source: KernelId, destination: KernelId, envelope: MessageEnvelope, audit_tag: AuditTag, ) -> Result<DeliveryReceipt>

Send a message stamped with an explicit audit tag (overriding the registration-time tag).

Useful for the same kernel participating in multiple engagements — e.g. a shared report-generation kernel that should bill different engagements depending on which request it’s serving.

Source

pub fn add_route(&self, destination: KernelId, next_hop: KernelId)

Add an indirect route inside the unspecified-tenant sub-broker (legacy API — single-tenant callers should use this).

Source

pub fn add_route_in( &self, tenant_id: TenantId, destination: KernelId, next_hop: KernelId, )

Add an indirect route inside a specific tenant’s sub-broker.

Source

pub fn remove_route(&self, destination: &KernelId)

Remove an indirect route from the unspecified-tenant sub-broker.

Source

pub fn remove_route_in(&self, tenant_id: TenantId, destination: &KernelId)

Remove an indirect route from a specific tenant’s sub-broker.

Source

pub fn stats(&self) -> K2KStats

Get aggregate stats across all sub-brokers.

Source

pub fn tenant_stats(&self, tenant_id: TenantId) -> Option<TenantStats>

Get per-tenant stats (useful for billing / dashboards).

Source

pub fn get_receipt(&self, message_id: &MessageId) -> Option<DeliveryReceipt>

Get delivery receipt for a message.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more