RpcSocket

Struct RpcSocket 

Source
pub struct RpcSocket { /* private fields */ }
Expand description

Bi-directional socket connection to a qrpc bus system

A connection is always between a component on the bus, and the broker. The broker listens to incoming connections, and relays them. A component (service, or utility library) can either operate only in sending mode, or listen as well, so that it can be used as a dependency by other services. The sending socket is used as a listener, meaning that no specific port needs to be bound for a service.

When using the server(...) constructor you bind a port, when attaching a lambda via listen(...) you use the established connection. In your service code there is no reason to ever use server(...)!

When sending a message, the socket will listen for a reply from the broker on the sending stream, to make sure that return data is properly associated. You can control the timeout via the connect_timeout function.

Implementations§

Source§

impl RpcSocket

Source

pub async fn connect(addr: &str, port: u16) -> RpcResult<Arc<Self>>

Create a client socket that connects to a remote broker

Source

pub async fn connect_timeout( addr: &str, port: u16, timeout: Duration, ) -> RpcResult<Arc<Self>>

Create a client socket with an explicit timeout

Source

pub async fn listen<F: Fn(Message) + Send + 'static>(self: &Arc<Self>, cb: F)

Attach a permanent listener to the sending stream

Source

pub async fn server<F, D>( addr: &str, port: u16, cb: F, data: D, ) -> RpcResult<Arc<Self>>
where F: Fn(TcpStream, D) + Send + Copy + 'static, D: Send + Sync + Clone + 'static,

Bind a socket to listen for connections

This function is primarily used by the qrpc-broker and should not be used in your service code. To listen for incoming connections on the outgoing stream (meaning client side), use listen(...)

Source

pub async fn reply(self: &Arc<Self>, msg: Message) -> RpcResult<()>

Send a message as a reply to a recipient

Source

pub async fn send<T, F>( self: &Arc<Self>, msg: Message, convert: F, ) -> RpcResult<T>
where F: Fn(Message) -> RpcResult<T>,

Send a message to the other side of this stream

This function is meant to be used by qrpc clients that only have a single connection stream to the broker. If you wanted to write an alternative message broker, you have to use the io utilities directly (as the qrpc-broker crate does)!

After sending a message this function will wait for a reply and parse the message for you. You must provide a conversion lambda so that the types can be extracted from the message type that the SDK receives.

Source

pub fn shutdown(self: &Arc<Self>)

Terminate all workers associated with this socket

Source

pub fn running(&self) -> bool

Get the current running state

Source

pub fn listening(&self) -> bool

Get the current listening state

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<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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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