Struct qrpc_sdk::RpcSocket[][src]

pub struct RpcSocket { /* fields omitted */ }

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

impl RpcSocket[src]

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

Create a client socket that connects to a remote broker

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

Create a client socket with an explicit timeout

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

Attach a permanent listener to the sending stream

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, 
[src]

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

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

Send a message as a reply to a recipient

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

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.

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

Terminate all workers associated with this socket

pub fn running(&self) -> bool[src]

Get the current running state

pub fn listening(&self) -> bool[src]

Get the current listening state

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,