pub struct SubscriptionStream { /* private fields */ }Expand description
A connected subscription whose background reader surfaces delivered messages.
Construct with SubscriptionStream::open; the background reader starts
immediately and runs until the stream is dropped. Pull delivered messages with
SubscriptionStream::recv_timeout.
Implementations§
Source§impl SubscriptionStream
impl SubscriptionStream
Source§impl SubscriptionStream
impl SubscriptionStream
Sourcepub fn open(
address: &str,
channel: &str,
accepted_schemas: Vec<SchemaId>,
) -> Result<Self, SdkError>
pub fn open( address: &str, channel: &str, accepted_schemas: Vec<SchemaId>, ) -> Result<Self, SdkError>
Connects to address, performs the handshake, subscribes to channel, and
starts the background reader that drains delivered messages.
accepted_schemas is the client’s schema-compatibility list; pass an empty
vector to let the server select the channel’s configured schema (the
server’s negotiation contract).
§Errors
Returns SdkError::Connection when the TCP connection or socket
configuration fails, and SdkError::Protocol when the handshake or
subscribe is rejected, or the socket cannot be cloned for the reader thread.
Sourcepub fn open_with_auth(
address: &str,
channel: &str,
accepted_schemas: Vec<SchemaId>,
auth_token: &[u8],
) -> Result<Self, SdkError>
pub fn open_with_auth( address: &str, channel: &str, accepted_schemas: Vec<SchemaId>, auth_token: &[u8], ) -> Result<Self, SdkError>
Connects, handshakes carrying auth_token, subscribes to channel, and
starts the background reader.
A subscription owns a dedicated connection (the v1 shape), so it presents
its own credential in its own Connect frame; the token a
request/response transport was built with lives on that transport’s
socket and cannot travel here. Additive to open: an empty token is
exactly the open-access handshake open performs, so an ungated server
sees byte-identical bytes either way.
The server compares the token during the handshake and answers a
mismatch with ConnectError before closing, which surfaces here as
SdkError::Connection.
accepted_schemas is the client’s schema-compatibility list; pass an
empty vector to let the server select the channel’s configured schema.
§Errors
Returns SdkError::Connection when the TCP connection or socket
configuration fails or the token is rejected, and SdkError::Protocol
when the subscribe is rejected, or the socket cannot be cloned for the
reader thread.
Sourcepub fn open_registered(
address: &str,
channel: &str,
accepted_schemas: Vec<SchemaId>,
registration: WorkerRegistration,
) -> Result<Self, SdkError>
pub fn open_registered( address: &str, channel: &str, accepted_schemas: Vec<SchemaId>, registration: WorkerRegistration, ) -> Result<Self, SdkError>
Connects, handshakes, registers the connection as the worker
registration names, then subscribes to channel, so the server can
tell which worker the subscription belongs to (a subscription owns its
own connection, so the worker’s push connection cannot say it).
§Errors
As open, and SdkError::Protocol when the server rejects the
registration (the reason is carried in the error).
Sourcepub fn recv_timeout(
&self,
timeout: Duration,
) -> Result<DeliveredMessage, SdkError>
pub fn recv_timeout( &self, timeout: Duration, ) -> Result<DeliveredMessage, SdkError>
Blocks up to timeout for the next delivered message from the server.
§Errors
Returns SdkError::Connection when no message arrives within
timeout. Once the reader has stopped and every held delivery has been
taken, returns the error it stopped with: the server’s mid-stream
SubscribeError, its Disconnect, the read or decode failure itself,
or SdkError::Backpressure naming a delivery too large for the
mailbox.
Sourcepub fn stats(&self) -> Result<MailboxStats, SdkError>
pub fn stats(&self) -> Result<MailboxStats, SdkError>
The mailbox counters: deliveries and bytes held now and at peak, how often the reader stopped reading for a consumer that had not made room, refused and stray frames, and errors no consumer was left to receive.
§Errors
Returns SdkError::Connection when the mailbox lock is poisoned.
Sourcepub const fn subscription_id(&self) -> u64
pub const fn subscription_id(&self) -> u64
The server-assigned id for this subscription.