razor_stream/lib.rs
1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![cfg_attr(docsrs, allow(unused_attributes))]
3
4//! # razor-stream
5//!
6//! This crate provides a low-level streaming interface for `razor-rpc`.
7//! It is used for stream processing and is part of the modular design of `razor-rpc`.
8//!
9//! If you are looking for a high-level remote API call interface, use [`razor-rpc`](https://docs.rs/razor-rpc) instead.
10//!
11//! ## Components
12//!
13//! `razor-rpc` is designed to be modular and pluggable. It is a collection of crates that provide different functionalities:
14//!
15//! - [`razor-rpc-codec`](https://docs.rs/razor-rpc-codec): Provides codecs for serialization, such as `msgpack`.
16//! - Async runtime support by [`orb`](https://docs.rs/orb):
17//! - [`orb-tokio`](https://docs.rs/orb-tokio): A runtime adapter for the `tokio` runtime.
18//! - [`orb-smol`](https://docs.rs/orb-smol): A runtime adapter for the `smol` runtime.
19//! - Transports can be implemented with a raw socket, without the overhead of the HTTP protocol:
20//! - [`razor-rpc-tcp`](https://docs.rs/razor-rpc-tcp): A TCP transport implementation.
21//!
22//! For Rpc tasks, we choose `Debug` instead of `Display` when logging, recommend use
23//! [format-attr](https://docs.rs/format-attr) to customized your message format.
24//!
25//! ## The Design
26//!
27//! Our implementation is designed to optimize throughput and lower
28//! CPU consumption for high-performance services.
29//!
30//! Each connection is a full-duplex, multiplexed stream.
31//! There's a `seq` ID assigned to a packet to track
32//! a request and response. The timeout of a packet is checked in batches every second.
33//! We utilize the [crossfire](https://docs.rs/crossfire) channel for parallelizing the work with
34//! coroutines.
35//!
36//! With an [ClientStream](crate::client::stream::ClientStream), the request packets sent in sequence,
37//! and wait with a sliding window throttler controlling the number of in-flight packets.
38//! An internal timer then registers the request through a channel, and when the response
39//! is received, it can optionally notify the user through a user-defined channel or another mechanism.
40//!
41//! [ConnPool](crate::client::ConnPool) and [FailoverPool](crate::client::FailoverPool) are provided on top of `ClientStream` for user.
42//!
43//! In an [RpcServer](crate::server::RpcServer), for each connection, there is one coroutine to read requests and one
44//! coroutine to write responses. Requests can be dispatched with a user-defined
45//! [Dispatch](crate::server::dispatch::Dispatch) trait implementation.
46//!
47//! Responses are received through a channel wrapped in [RespNoti](crate::server::task::RespNoti).
48//!
49//! ## Protocol
50//!
51//! The details are described in [crate::proto].
52//!
53//! Also see the [error module](crate::error) for details on built-in error types and custom error type
54//! examples.
55//!
56//! ## Usage
57//!
58//! You can refer to the [test case](https://github.com/NaturalIO/razor-rpc/blob/master/test-suite/src/stream/) for example.
59//!
60
61#[macro_use]
62extern crate captains_log;
63
64pub mod buffer;
65pub mod client;
66pub mod error;
67pub mod proto;
68pub mod server;
69// re-export for macros, so that user don't need to use multiple crates
70pub use razor_rpc_codec::Codec;