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: u64Unique 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: ServerConfigServer configuration (heartbeat, limits, topic defaults, etc.).
metrics: Arc<Metrics>Metrics counters for connection, message, and error tracking.
ack_manager: SharedAckManagerAcknowledgement 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: BackpressureControllerBackpressure controller for monitoring the outbound queue.
sink_id: u64Unique 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
impl Connection
Sourcepub 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
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.
Sourcepub fn sink(&self) -> Arc<dyn FanoutSink> ⓘ
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.
Sourcepub async fn run(self, transport: Box<dyn TransportConnection>) -> Result<()>
pub async fn run(self, transport: Box<dyn TransportConnection>) -> Result<()>
Run the full connection lifecycle.
This method:
- Increments connection metrics.
- Performs the hello handshake (protocol negotiation, auth, resume).
- Spawns the writer and reader tasks.
- Waits for the reader to finish.
- Closes the transport, releases resources (sink, acks, resume, per-topic publisher slots), and decrements connection metrics.
- Returns the reader’s result.