Skip to main content

Connection

Struct Connection 

Source
pub struct Connection {
    pub conn_id: u64,
    pub broker: Arc<dyn Broker>,
    pub auth: Arc<dyn AuthProvider>,
    pub config: ServerConfig,
    pub metrics: Arc<Metrics>,
    pub ack_manager: SharedAckManager,
    pub resume: Arc<ResumeManager>,
    pub offset_tracker: Arc<OffsetTracker>,
    pub backpressure: BackpressureController,
    pub sink_id: u64,
    pub codec: Arc<dyn Codec>,
    /* private fields */
}
Expand description

Per-connection state.

Each accepted transport connection is wrapped in a Connection which holds every resource the connection needs during its lifetime: the broker, auth provider, server config, metrics, ack/resume managers, backpressure controller, and the negotiated codec.

The connection is consumed by run which drives the full lifecycle (handshake, active phase, teardown).

Fields§

§conn_id: u64

Unique connection id within this process, assigned by the server.

§broker: Arc<dyn Broker>

Reference to the broker that routes messages between publishers and subscribers.

§auth: Arc<dyn AuthProvider>

Authentication provider used during the hello handshake.

§config: ServerConfig

Server configuration (heartbeat, limits, topic defaults, etc.).

§metrics: Arc<Metrics>

Metrics counters for connection, message, and error tracking.

§ack_manager: SharedAckManager

Acknowledgement manager for tracking outstanding (sent-but-not-acked) frames.

§resume: Arc<ResumeManager>

Shared resume manager for evaluating session resume requests.

§offset_tracker: Arc<OffsetTracker>

Shared offset tracker for recording per-session per-topic offset progress. Persists across connections for cross-connection resume.

§backpressure: BackpressureController

Backpressure controller for monitoring the outbound queue.

§sink_id: u64

Unique sink id for this connection’s fanout sink.

§codec: Arc<dyn Codec>

Negotiated codec, defaulting to JSON until the handshake completes.

Implementations§

Source§

impl Connection

Source

pub fn new( conn_id: u64, broker: Arc<dyn Broker>, auth: Arc<dyn AuthProvider>, config: ServerConfig, metrics: Arc<Metrics>, ack_manager: SharedAckManager, resume: Arc<ResumeManager>, offset_tracker: Arc<OffsetTracker>, session_store: SessionStore, ) -> Self

Create a new connection with the given parameters.

A bounded mpsc channel (capacity 1024) is created for the outbound frame queue. The backpressure controller is initialized with the max_send_queue_bytes from the server config.

Source

pub fn sink(&self) -> Arc<dyn FanoutSink>

Create a FanoutSink attached to this connection’s outbound channel.

The sink can be handed to the broker so that subscription fanout can push frames directly into the connection’s write queue. The sink enforces the backpressure limit and increments the messages_out_total metric on each successful delivery.

Source

pub async fn run(self, transport: Box<dyn TransportConnection>) -> Result<()>

Run the full connection lifecycle.

This method:

  1. Increments connection metrics.
  2. Performs the hello handshake (protocol negotiation, auth, resume).
  3. Spawns the writer and reader tasks.
  4. Waits for the reader to finish.
  5. Closes the transport, releases resources (sink, acks, resume, per-topic publisher slots), and decrements connection metrics.
  6. Returns the reader’s result.

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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