Skip to main content

PushClient

Struct PushClient 

Source
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

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn writer_handle(&self) -> PushWriter

A cheap, cloneable handle to this push connection’s write half, for background tasks that publish out-of-band frames on the same socket without owning the full client (which cannot be cloned — it holds the reader thread join handle).

The returned PushWriter shares the client’s Arc<Mutex<TcpStream>>, so a frame it writes travels the SAME connection the server pushes on. It is the worker’s observability-drain leg: a drain task holds one and publishes each OBSERVABILITY_CHANNEL event live while the client keeps serving pushes.

Source

pub fn publish(&self, channel: &str, payload: Vec<u8>) -> Result<(), SdkError>

Publish payload to channel over this connection (out-of-band from the push/reply round trip).

Convenience shorthand for self.writer_handle().publish(channel, payload).

§Errors

Returns SdkError::Protocol when the publish frame cannot be encoded and SdkError::Connection when it cannot be written to the socket or the writer lock is poisoned.

Trait Implementations§

Source§

impl Debug for PushClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for PushClient

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more