pub struct PushClient { /* private fields */ }Expand description
A connected client that consumes server pushes and sends correlated replies.
Construct with PushClient::connect; the background reader starts
immediately and runs until the client is dropped. Pull pushed frames with
PushClient::recv_timeout and answer them with PushClient::reply.
Implementations§
Source§impl PushClient
impl PushClient
Sourcepub fn connect(address: &str) -> Result<Self, SdkError>
pub fn connect(address: &str) -> Result<Self, SdkError>
Connects to address, performs the protocol handshake, and starts the
background reader that drains inbound server pushes.
§Errors
Returns SdkError::Connection when the TCP connection or socket
configuration fails, and SdkError::Protocol when the handshake is
rejected or the socket cannot be cloned for the reader thread.
Sourcepub fn connect_with_registration(
address: &str,
registration: WorkerRegistration,
) -> Result<Self, SdkError>
pub fn connect_with_registration( address: &str, registration: WorkerRegistration, ) -> Result<Self, SdkError>
Connects, performs the handshake, then synchronously registers this client as a worker before starting the background reader.
This mirrors the synchronous Connect/ConnectAck pattern: the
WorkerRegister frame is written and its Frame::WorkerRegisterAck read
on the calling thread, BEFORE the Push-only background reader is spawned, so
the ack is never swallowed by the reader. A connect-variant (rather than a
register() method on a connected client) is the cleanest fit: connect
spawns the reader as its last step, so registration must be threaded into
the connect sequence to land before that spawn; a post-connect method would
race the already-running reader for the ack frame.
§Errors
Returns SdkError::Connection when the TCP connection or socket
configuration fails, and SdkError::Protocol when the handshake is
rejected, the server rejects the registration (the rejection reason is
carried in the error), or the socket cannot be cloned for the reader thread.
Sourcepub fn recv_timeout(&self, timeout: Duration) -> Result<PushedFrame, SdkError>
pub fn recv_timeout(&self, timeout: Duration) -> Result<PushedFrame, SdkError>
Blocks up to timeout for the next pushed frame from the server.
§Errors
Returns SdkError::Connection when no push arrives within timeout or
the background reader has stopped (e.g. the server closed the connection).
Sourcepub fn reply(
&self,
correlation_id: u64,
payload: Vec<u8>,
) -> Result<(), SdkError>
pub fn reply( &self, correlation_id: u64, payload: Vec<u8>, ) -> Result<(), SdkError>
Sends a correlated reply to a pushed frame, echoing its correlation id so the server matches the reply back to the originating push.
§Errors
Returns SdkError::Protocol when the reply frame cannot be encoded and
SdkError::Connection when it cannot be written to the socket or the
writer lock is poisoned.