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 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.