mirror of
https://github.com/OMGeeky/tarpc.git
synced 2025-12-26 17:02:32 +01:00
Unite most of tarpc into a single crate
This commit is contained in:
@@ -2,10 +2,6 @@
|
||||
|
||||
members = [
|
||||
"example-service",
|
||||
"rpc",
|
||||
"trace",
|
||||
"bincode-transport",
|
||||
"json-transport",
|
||||
"tarpc",
|
||||
"plugins",
|
||||
]
|
||||
|
||||
@@ -41,13 +41,13 @@ Some other features of tarpc:
|
||||
sends a request to another server, that server will see an 8s deadline.
|
||||
- Serde serialization: enabling the `serde1` Cargo feature will make service requests and
|
||||
responses `Serialize + Deserialize`. It's entirely optional, though: in-memory transports can
|
||||
be used, as well, so the price of eerialization doesn't have to be paid when it's not needed.
|
||||
be used, as well, so the price of serialization doesn't have to be paid when it's not needed.
|
||||
|
||||
### Usage
|
||||
Add to your `Cargo.toml` dependencies:
|
||||
|
||||
```toml
|
||||
tarpc = "0.18.0"
|
||||
tarpc = { version = "0.18.0", features = ["full"] }
|
||||
```
|
||||
|
||||
The `tarpc::service` attribute expands to a collection of items that form an rpc service.
|
||||
@@ -114,10 +114,7 @@ impl World for HelloServer {
|
||||
Lastly let's write our `main` that will start the server. While this example uses an
|
||||
[in-process
|
||||
channel](https://docs.rs/tarpc/0.18.0/tarpc/transport/channel/struct.UnboundedChannel.html),
|
||||
tarpc also ships
|
||||
[bincode](https://docs.rs/tarpc-bincode-transport/0.7.0/tarpc_bincode_transport/)
|
||||
and
|
||||
[JSON](https://docs.rs/tarpc-json-transport/0.1.0/tarpc_json_transport)
|
||||
tarpc also ships bincode and JSON
|
||||
tokio-net based TCP transports that are generic over all serializable types.
|
||||
|
||||
```rust
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
[package]
|
||||
name = "tarpc-bincode-transport"
|
||||
version = "0.7.0"
|
||||
authors = ["Tim Kuehn <tikue@google.com>"]
|
||||
edition = '2018'
|
||||
license = "MIT"
|
||||
documentation = "https://docs.rs/tarpc-bincode-transport"
|
||||
homepage = "https://github.com/google/tarpc"
|
||||
repository = "https://github.com/google/tarpc"
|
||||
keywords = ["rpc", "network", "bincode", "serde", "tarpc"]
|
||||
categories = ["asynchronous", "network-programming"]
|
||||
readme = "../README.md"
|
||||
description = "A bincode-based transport for tarpc services."
|
||||
|
||||
[dependencies]
|
||||
futures-preview = { version = "0.3.0-alpha.18", features = ["compat"] }
|
||||
futures_legacy = { version = "0.1", package = "futures" }
|
||||
pin-project = "0.4"
|
||||
serde = "1.0"
|
||||
tokio-io = "0.1"
|
||||
async-bincode = "0.4"
|
||||
tokio-tcp = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
futures-test-preview = { version = "0.3.0-alpha.18" }
|
||||
assert_matches = "1.0"
|
||||
pin-utils = "0.1.0-alpha"
|
||||
@@ -1 +0,0 @@
|
||||
edition = "2018"
|
||||
@@ -13,11 +13,10 @@ readme = "../README.md"
|
||||
description = "An example server built on tarpc."
|
||||
|
||||
[dependencies]
|
||||
tarpc-json-transport = { version = "0.1", path = "../json-transport" }
|
||||
clap = "2.0"
|
||||
futures-preview = { version = "0.3.0-alpha.18" }
|
||||
serde = { version = "1.0" }
|
||||
tarpc = { version = "0.18", path = "../tarpc", features = ["serde1"] }
|
||||
tarpc = { version = "0.18", path = "../tarpc", features = ["json-transport", "serde1"] }
|
||||
tokio = "0.2.0-alpha.3"
|
||||
env_logger = "0.6"
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ async fn main() -> io::Result<()> {
|
||||
|
||||
let name = flags.value_of("name").unwrap().into();
|
||||
|
||||
let transport = tarpc_json_transport::connect(server_addr).await?;
|
||||
let transport = tarpc::json_transport::connect(server_addr).await?;
|
||||
|
||||
// WorldClient is generated by the service attribute. It has a constructor `new` that takes a
|
||||
// config and any Transport as input.
|
||||
|
||||
@@ -64,9 +64,9 @@ async fn main() -> io::Result<()> {
|
||||
|
||||
let server_addr = (IpAddr::from([0, 0, 0, 0]), port);
|
||||
|
||||
// tarpc_json_transport is provided by the associated crate tarpc-json-transport. It makes it easy
|
||||
// JSON transport is provided by the json_transport tarpc module. It makes it easy
|
||||
// to start up a serde-powered json serialization strategy over TCP.
|
||||
tarpc_json_transport::listen(&server_addr)
|
||||
tarpc::json_transport::listen(&server_addr)
|
||||
.await?
|
||||
// Ignore accept errors.
|
||||
.filter_map(|r| future::ready(r.ok()))
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
[package]
|
||||
name = "tarpc-json-transport"
|
||||
version = "0.1.0"
|
||||
authors = ["Artem Vorotnikov <artem@vorotnikov.me>"]
|
||||
edition = '2018'
|
||||
license = "MIT"
|
||||
documentation = "https://docs.rs/tarpc-json-transport"
|
||||
homepage = "https://github.com/google/tarpc"
|
||||
repository = "https://github.com/google/tarpc"
|
||||
keywords = ["rpc", "network", "json", "serde", "tarpc"]
|
||||
categories = ["asynchronous", "network-programming"]
|
||||
readme = "../README.md"
|
||||
description = "A JSON-based transport for tarpc services."
|
||||
|
||||
[dependencies]
|
||||
futures-preview = "0.3.0-alpha"
|
||||
pin-project = "0.4"
|
||||
serde = "1"
|
||||
serde_json = "1"
|
||||
tokio = { version = "0.2.0-alpha", default-features = false, features = ["codec", "io", "net"] }
|
||||
tokio-net = "0.2.0-alpha"
|
||||
tokio-serde-json = "0.3"
|
||||
|
||||
[dev-dependencies]
|
||||
pin-utils = "0.1.0-alpha"
|
||||
assert_matches = "1.0"
|
||||
@@ -1 +0,0 @@
|
||||
edition = "2018"
|
||||
@@ -1,37 +0,0 @@
|
||||
[package]
|
||||
name = "tarpc-lib"
|
||||
version = "0.6.1"
|
||||
authors = ["Tim Kuehn <tikue@google.com>"]
|
||||
edition = '2018'
|
||||
license = "MIT"
|
||||
documentation = "https://docs.rs/tarpc-lib"
|
||||
homepage = "https://github.com/google/tarpc"
|
||||
repository = "https://github.com/google/tarpc"
|
||||
keywords = ["rpc", "network", "server", "api", "microservices"]
|
||||
categories = ["asynchronous", "network-programming"]
|
||||
readme = "../README.md"
|
||||
description = "An RPC framework for Rust with a focus on ease of use."
|
||||
|
||||
[features]
|
||||
default = []
|
||||
serde1 = ["trace/serde", "serde", "serde/derive"]
|
||||
tokio1 = ["tokio"]
|
||||
|
||||
[dependencies]
|
||||
fnv = "1.0"
|
||||
futures-preview = { version = "0.3.0-alpha.18" }
|
||||
humantime = "1.0"
|
||||
log = "0.4"
|
||||
pin-project = "0.4"
|
||||
raii-counter = "0.2"
|
||||
rand = "0.7"
|
||||
tokio-timer = "0.3.0-alpha.4"
|
||||
trace = { package = "tarpc-trace", version = "0.2", path = "../trace" }
|
||||
serde = { optional = true, version = "1.0" }
|
||||
tokio = { optional = true, version = "0.2.0-alpha.4" }
|
||||
|
||||
[dev-dependencies]
|
||||
futures-test-preview = { version = "0.3.0-alpha.18" }
|
||||
env_logger = "0.6"
|
||||
assert_matches = "1.0"
|
||||
pin-utils = "0.1.0-alpha"
|
||||
@@ -1 +0,0 @@
|
||||
edition = "2018"
|
||||
@@ -13,28 +13,49 @@ readme = "../README.md"
|
||||
description = "An RPC framework for Rust with a focus on ease of use."
|
||||
|
||||
[features]
|
||||
default = ["tokio1"]
|
||||
serde1 = ["rpc/serde1", "tarpc-plugins/serde1", "serde", "serde/derive"]
|
||||
tokio1 = ["rpc/tokio1"]
|
||||
default = []
|
||||
|
||||
serde1 = ["tarpc-plugins/serde1", "serde", "serde/derive"]
|
||||
tokio1 = ["tokio"]
|
||||
bincode-transport = ["async-bincode", "futures-legacy", "futures-test-preview", "futures-preview/compat", "tokio-io", "tokio-tcp"]
|
||||
json-transport = ["tokio/codec", "tokio/io", "tokio/net", "tokio-net", "tokio-serde-json"]
|
||||
|
||||
full = ["serde1", "tokio1", "bincode-transport", "json-transport"]
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "google/tarpc" }
|
||||
|
||||
[dependencies]
|
||||
serde = { optional = true, version = "1.0" }
|
||||
rpc = { package = "tarpc-lib", path = "../rpc", version = "0.6" }
|
||||
tarpc-plugins = { path = "../plugins", version = "0.5.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.0"
|
||||
tarpc-json-transport = { version = "0.1", path = "../json-transport" }
|
||||
bytes = { version = "0.4", features = ["serde"] }
|
||||
env_logger = "0.6"
|
||||
fnv = "1.0"
|
||||
futures-preview = { version = "0.3.0-alpha.18" }
|
||||
humantime = "1.0"
|
||||
log = "0.4"
|
||||
pin-utils = "0.1.0-alpha.4"
|
||||
tokio = "0.2.0-alpha.3"
|
||||
pin-project = "0.4"
|
||||
raii-counter = "0.2"
|
||||
rand = "0.7"
|
||||
tokio-timer = "0.3.0-alpha"
|
||||
serde = { optional = true, version = "1.0", features = ["derive"] }
|
||||
tokio = { optional = true, version = "0.2.0-alpha" }
|
||||
tarpc-plugins = { path = "../plugins" }
|
||||
|
||||
async-bincode = { optional = true, version = "0.4" }
|
||||
futures-legacy = { optional = true, version = "0.1", package = "futures" }
|
||||
futures-test-preview = { optional = true, version = "0.3.0-alpha" }
|
||||
tokio-io = { optional = true, version = "0.1" }
|
||||
tokio-tcp = { optional = true, version = "0.1" }
|
||||
|
||||
tokio-net = { optional = true, version = "0.2.0-alpha" }
|
||||
tokio-serde-json = { optional = true, version = "0.3" }
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.0"
|
||||
bytes = { version = "0.4", features = ["serde"] }
|
||||
env_logger = "0.6"
|
||||
futures-preview = { version = "0.3.0-alpha" }
|
||||
humantime = "1.0"
|
||||
log = "0.4"
|
||||
pin-utils = "0.1.0-alpha"
|
||||
tokio = "0.2.0-alpha"
|
||||
|
||||
[[example]]
|
||||
name = "server_calling_server"
|
||||
|
||||
@@ -59,7 +59,7 @@ impl subscriber::Subscriber for Subscriber {
|
||||
|
||||
impl Subscriber {
|
||||
async fn listen(id: u32, config: server::Config) -> io::Result<SocketAddr> {
|
||||
let incoming = tarpc_json_transport::listen("0.0.0.0:0")
|
||||
let incoming = tarpc::json_transport::listen("0.0.0.0:0")
|
||||
.await?
|
||||
.filter_map(|r| future::ready(r.ok()));
|
||||
let addr = incoming.get_ref().local_addr();
|
||||
@@ -114,7 +114,7 @@ impl publisher::Publisher for Publisher {
|
||||
id: u32,
|
||||
addr: SocketAddr,
|
||||
) -> io::Result<()> {
|
||||
let conn = tarpc_json_transport::connect(addr).await?;
|
||||
let conn = tarpc::json_transport::connect(addr).await?;
|
||||
let subscriber =
|
||||
subscriber::SubscriberClient::new(client::Config::default(), conn).spawn()?;
|
||||
eprintln!("Subscribing {}.", id);
|
||||
@@ -146,7 +146,7 @@ impl publisher::Publisher for Publisher {
|
||||
async fn main() -> io::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
let transport = tarpc_json_transport::listen("0.0.0.0:0")
|
||||
let transport = tarpc::json_transport::listen("0.0.0.0:0")
|
||||
.await?
|
||||
.filter_map(|r| future::ready(r.ok()));
|
||||
let publisher_addr = transport.get_ref().local_addr();
|
||||
@@ -160,7 +160,7 @@ async fn main() -> io::Result<()> {
|
||||
let subscriber1 = Subscriber::listen(0, server::Config::default()).await?;
|
||||
let subscriber2 = Subscriber::listen(1, server::Config::default()).await?;
|
||||
|
||||
let publisher_conn = tarpc_json_transport::connect(publisher_addr);
|
||||
let publisher_conn = tarpc::json_transport::connect(publisher_addr);
|
||||
let publisher_conn = publisher_conn.await?;
|
||||
let mut publisher =
|
||||
publisher::PublisherClient::new(client::Config::default(), publisher_conn).spawn()?;
|
||||
|
||||
@@ -39,9 +39,9 @@ impl World for HelloServer {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
// tarpc_json_transport is provided by the associated crate json-transport. It makes it
|
||||
// tarpc_json_transport is provided by the associated crate json_transport. It makes it
|
||||
// easy to start up a serde-powered JSON serialization strategy over TCP.
|
||||
let mut transport = tarpc_json_transport::listen("0.0.0.0:0").await?;
|
||||
let mut transport = tarpc::json_transport::listen("0.0.0.0:0").await?;
|
||||
let addr = transport.local_addr();
|
||||
|
||||
let server = async move {
|
||||
@@ -61,7 +61,7 @@ async fn main() -> io::Result<()> {
|
||||
};
|
||||
tokio::spawn(server);
|
||||
|
||||
let transport = tarpc_json_transport::connect(addr).await?;
|
||||
let transport = tarpc::json_transport::connect(addr).await?;
|
||||
|
||||
// WorldClient is generated by the tarpc::service attribute. It has a constructor `new` that
|
||||
// takes a config and any Transport as input.
|
||||
|
||||
@@ -66,7 +66,7 @@ impl DoubleService for DoubleServer {
|
||||
async fn main() -> io::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
let add_listener = tarpc_json_transport::listen("0.0.0.0:0")
|
||||
let add_listener = tarpc::json_transport::listen("0.0.0.0:0")
|
||||
.await?
|
||||
.filter_map(|r| future::ready(r.ok()));
|
||||
let addr = add_listener.get_ref().local_addr();
|
||||
@@ -76,20 +76,20 @@ async fn main() -> io::Result<()> {
|
||||
.respond_with(AddServer.serve());
|
||||
tokio::spawn(add_server);
|
||||
|
||||
let to_add_server = tarpc_json_transport::connect(addr).await?;
|
||||
let to_add_server = tarpc::json_transport::connect(addr).await?;
|
||||
let add_client = add::AddClient::new(client::Config::default(), to_add_server).spawn()?;
|
||||
|
||||
let double_listener = tarpc_json_transport::listen("0.0.0.0:0")
|
||||
let double_listener = tarpc::json_transport::listen("0.0.0.0:0")
|
||||
.await?
|
||||
.filter_map(|r| future::ready(r.ok()));
|
||||
let addr = double_listener.get_ref().local_addr();
|
||||
let double_server = rpc::Server::default()
|
||||
let double_server = tarpc::Server::default()
|
||||
.incoming(double_listener)
|
||||
.take(1)
|
||||
.respond_with(DoubleServer { add_client }.serve());
|
||||
tokio::spawn(double_server);
|
||||
|
||||
let to_double_server = tarpc_json_transport::connect(addr).await?;
|
||||
let to_double_server = tarpc::json_transport::connect(addr).await?;
|
||||
let mut double_client =
|
||||
double::DoubleClient::new(client::Config::default(), to_double_server).spawn()?;
|
||||
|
||||
|
||||
@@ -203,10 +203,18 @@
|
||||
//!
|
||||
//! Use `cargo doc` as you normally would to see the documentation created for all
|
||||
//! items expanded by a `service!` invocation.
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#![deny(missing_docs, missing_debug_implementations)]
|
||||
pub mod rpc;
|
||||
pub use rpc::*;
|
||||
|
||||
#[cfg(feature = "bincode-transport")]
|
||||
pub mod bincode_transport;
|
||||
#[cfg(feature = "json-transport")]
|
||||
pub mod json_transport;
|
||||
|
||||
pub mod trace;
|
||||
|
||||
/// The main macro that creates RPC services.
|
||||
///
|
||||
/// Rpc methods are specified, mirroring trait syntax:
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
use crate::{
|
||||
context,
|
||||
trace::SpanId,
|
||||
util::{Compact, TimeUntil},
|
||||
ClientMessage, PollIo, Request, Response, Transport,
|
||||
};
|
||||
@@ -29,7 +30,6 @@ use std::{
|
||||
},
|
||||
};
|
||||
use tokio_timer::{timeout, Timeout};
|
||||
use trace::SpanId;
|
||||
|
||||
use super::{Config, NewClient};
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
//! Provides a request context that carries a deadline and trace context. This context is sent from
|
||||
//! client to server and is used by the server to enforce response deadlines.
|
||||
|
||||
use crate::trace::{self, TraceId};
|
||||
use std::time::{Duration, SystemTime};
|
||||
use trace::{self, TraceId};
|
||||
|
||||
/// A request context that carries request-scoped information like deadlines and trace information.
|
||||
/// It is sent from client to server and is used by the server to enforce response deadlines.
|
||||
@@ -30,7 +30,7 @@ pub mod server;
|
||||
pub mod transport;
|
||||
pub(crate) mod util;
|
||||
|
||||
pub use crate::{client::Client, server::Server, transport::sealed::Transport};
|
||||
pub use crate::{client::Client, server::Server, trace, transport::sealed::Transport};
|
||||
|
||||
use futures::task::Poll;
|
||||
use std::{io, time::SystemTime};
|
||||
@@ -7,8 +7,8 @@
|
||||
//! Provides a server that concurrently handles many connections sending multiplexed requests.
|
||||
|
||||
use crate::{
|
||||
context, util::Compact, util::TimeUntil, ClientMessage, PollIo, Request, Response, ServerError,
|
||||
Transport,
|
||||
context, trace, util::Compact, util::TimeUntil, ClientMessage, PollIo, Request, Response,
|
||||
ServerError, Transport,
|
||||
};
|
||||
use fnv::FnvHashMap;
|
||||
use futures::{
|
||||
@@ -6,7 +6,7 @@ use futures::{
|
||||
use std::{io, rc::Rc};
|
||||
use tarpc::{
|
||||
client::{self, NewClient},
|
||||
context,
|
||||
context, json_transport,
|
||||
server::{self, BaseChannel, Channel, Handler},
|
||||
transport::channel,
|
||||
};
|
||||
@@ -61,7 +61,7 @@ async fn sequential() -> io::Result<()> {
|
||||
async fn serde() -> io::Result<()> {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let transport = tarpc_json_transport::listen("0.0.0.0:56789").await?;
|
||||
let transport = json_transport::listen("0.0.0.0:56789").await?;
|
||||
let addr = transport.local_addr();
|
||||
tokio::spawn(
|
||||
tarpc::Server::default()
|
||||
@@ -69,7 +69,7 @@ async fn serde() -> io::Result<()> {
|
||||
.respond_with(Server.serve()),
|
||||
);
|
||||
|
||||
let transport = tarpc_json_transport::connect(addr).await?;
|
||||
let transport = json_transport::connect(addr).await?;
|
||||
let mut client = ServiceClient::new(client::Config::default(), transport).spawn()?;
|
||||
|
||||
assert_matches!(client.add(context::current(), 1, 2).await, Ok(3));
|
||||
@@ -87,7 +87,7 @@ async fn concurrent() -> io::Result<()> {
|
||||
|
||||
let (tx, rx) = channel::unbounded();
|
||||
tokio::spawn(
|
||||
rpc::Server::default()
|
||||
tarpc::Server::default()
|
||||
.incoming(stream::once(ready(rx)))
|
||||
.respond_with(Server.serve()),
|
||||
);
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
[package]
|
||||
name = "tarpc-trace"
|
||||
version = "0.2.0"
|
||||
authors = ["tikue <tikue@google.com>"]
|
||||
edition = '2018'
|
||||
license = "MIT"
|
||||
documentation = "https://docs.rs/tarpc-trace"
|
||||
homepage = "https://github.com/google/tarpc"
|
||||
repository = "https://github.com/google/tarpc"
|
||||
keywords = ["rpc", "network", "server", "api", "tls"]
|
||||
categories = ["asynchronous", "network-programming"]
|
||||
readme = "../README.md"
|
||||
description = "foundations for tracing in tarpc"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.7"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
optional = true
|
||||
features = ["derive"]
|
||||
@@ -1 +0,0 @@
|
||||
edition = "2018"
|
||||
Reference in New Issue
Block a user