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
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 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
or the background reader has stopped (e.g. the server closed the stream).
Sourcepub const fn subscription_id(&self) -> u64
pub const fn subscription_id(&self) -> u64
The server-assigned id for this subscription.