| Crates.io | zus-rs |
| lib.rs | zus-rs |
| version | 1.1.4 |
| created_at | 2026-01-21 11:45:18.824948+00 |
| updated_at | 2026-01-21 12:19:27.172811+00 |
| description | ZUS RPC Framework - Rust implementation with cross-language compatibility |
| homepage | |
| repository | https://github.com/zus-dev/zus-rs |
| max_upload_size | |
| id | 2058965 |
| size | 86,186 |
ZUS-RS is a high-performance, cross-language RPC framework for Rust with compatibility for Java and C++ implementations. It provides service discovery via ZooServer and supports QuickLZ/Snappy compression.
Add zus-rs to your Cargo.toml:
[dependencies]
zus-rs = "1.1.4"
tokio = { version = "1.35", features = ["full"] }
Or choose specific features:
# Just client
[dependencies]
zus-rs = { version = "1.1.4", features = ["client"] }
# Just server
[dependencies]
zus-rs = { version = "1.1.4", features = ["server"] }
# Protocol only (no RPC runtime)
[dependencies]
zus-rs = { version = "1.1.4", features = ["protocol"] }
ZUS-RS supports two connection styles, matching the C++ and Java implementations:
tcp://host:port or tcp://host1:port1,host2:port2 (comma-separated for multiple endpoints)zns://zooserver:port/service/path/use bytes::Bytes;
use zus_rs::RpcClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Connect to a single service directly
let client = RpcClient::new("tcp://localhost:9527").await?;
// Or connect to multiple endpoints (manual load balancing)
// let client = RpcClient::new("tcp://host1:9527,host2:9527").await?;
// Make RPC call
let request = Bytes::from("Hello, World!");
let response = client.sync_call("echo", request, 5000).await?;
println!("Response: {}", String::from_utf8_lossy(&response));
Ok(())
}
use bytes::Bytes;
use zus_rs::RpcClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Connect via ZooServer - service discovery happens automatically
let client = RpcClient::new(
"zns://localhost:9528/zus/services/myservice/"
).await?;
// The client automatically:
// - Discovers all available service instances from ZooServer
// - Monitors their health (every 3 seconds)
// - Load balances requests across healthy instances (round-robin)
// - Handles service instances joining/leaving dynamically
// Make RPC call (same API regardless of connection style)
let request = Bytes::from("Hello, World!");
let response = client.sync_call("echo", request, 5000).await?;
println!("Response: {}", String::from_utf8_lossy(&response));
Ok(())
}
use bytes::Bytes;
use std::sync::Arc;
use zus_rs::{RpcServer, prelude::*};
struct EchoService;
#[async_trait]
impl Service for EchoService {
fn service_name(&self) -> &str {
"EchoService"
}
async fn do_work(
&self,
method: &str,
params: Bytes,
_context: zus_rs::server::RequestContext,
) -> zus_common::Result<Bytes> {
match method {
"echo" => Ok(params),
_ => Err(zus_common::ZusError::MethodNotFound(method.to_string())),
}
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Start server without ZooServer - clients connect via tcp://host:9527
let mut server = RpcServer::new("0.0.0.0".to_string(), 9527);
server.register_service(Arc::new(EchoService));
server.start().await?;
Ok(())
}
use bytes::Bytes;
use std::sync::Arc;
use zus_rs::{RpcServer, prelude::*};
use zus_discovery::ZusZooClient;
struct EchoService;
#[async_trait]
impl Service for EchoService {
fn service_name(&self) -> &str {
"EchoService"
}
async fn do_work(
&self,
method: &str,
params: Bytes,
_context: zus_rs::server::RequestContext,
) -> zus_common::Result<Bytes> {
match method {
"echo" => Ok(params),
_ => Err(zus_common::ZusError::MethodNotFound(method.to_string())),
}
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Connect to ZooServer
let zoo_client = Arc::new(
ZusZooClient::new(vec!["localhost:9528".to_string()]).await?
);
// Start server WITH ZooServer registration
// Server will automatically register at /zus/services/rust/0.0.0.0:9527
let mut server = RpcServer::new("0.0.0.0".to_string(), 9527)
.with_zoo_client(zoo_client);
server.register_service(Arc::new(EchoService));
server.start().await?;
Ok(())
}
To use Style 2 (ZooServer-based discovery), you need a running ZooServer instance. ZUS-RS includes a production-ready ZooServer implementation.
# Run with default settings (binds to 0.0.0.0:9528)
cargo run --bin zooserver
# Run with a config file
cargo run --bin zooserver -- path/to/config.cfg
# Run with debug logging
RUST_LOG=debug cargo run --bin zooserver
Create a .cfg file to customize ZooServer:
[zusnet]
# Maximum concurrent connections (default: 1000)
maxconnects=1000
# Idle connection timeout in seconds (default: 60)
idleconntimeout=60
# Enable compression (default: true)
COMPRESS=true
# Compression threshold in bytes (default: 4096)
COMPRESS_THRESHSIZE=4096
[zooserver]
# Server listening port (default: 9528)
srvport=9528
# Terminal 1: Start ZooServer
cargo run --bin zooserver
# Terminal 2: Start your service (registers with ZooServer)
cargo run --bin your-service
# Terminal 3: Run client (discovers service via ZooServer)
cargo run --bin your-client
/zus/services/myservice/tcp:host:portSyncPathFor more details, see zooserver/README.md.
Choose the features you need to minimize dependencies:
| Feature | Description | Use Case |
|---|---|---|
default |
Client + Server + Protocol | Full-featured applications |
minimal |
Protocol definitions only | Message definitions for FFI |
protocol |
Protocol + Codec + Compression | Custom transport layer |
client |
RPC client functionality | Client applications |
server |
RPC server functionality | Service implementations |
full |
Everything | Development and testing |
# Microservice (server only)
[dependencies]
zus-rs = { version = "1.1.4", features = ["server"] }
# Client application
[dependencies]
zus-rs = { version = "1.1.4", features = ["client"] }
# Protocol implementation (custom transport)
[dependencies]
zus-rs = { version = "1.1.4", features = ["protocol"] }
# Minimal (just message definitions)
[dependencies]
zus-rs = { version = "1.1.4", features = ["minimal"] }
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β zus-rs (convenience) β
β Feature flags: minimal, protocol, client, serverβ
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββ
β β β
β β β
βββββββββββ βββββββββββ ββββββββββββ
β client β β server β β protocol β
β feature β β feature β β feature β
βββββββββββ βββββββββββ ββββββββββββ
β β β
ββββββββββββββββΌβββββββββββββββ
β
ββββββββββββββββββββββββββββββββ
β zus-rpc-{client,server} β
β zus-discovery (ZooServer) β
β zus-common (codec/compress) β
β zus-proto (protobuf msgs) β
ββββββββββββββββββββββββββββββββ
use zus_rs::proto; // Protocol Buffer definitions (always available)
use zus_rs::common; // Codec and compression (protocol feature)
use zus_rs::discovery; // ZooServer client (client/server features)
use zus_rs::client; // RPC client (client feature)
use zus_rs::server; // RPC server (server feature)
// Or use the prelude for common imports
use zus_rs::prelude::*;
ZUS-RS is wire-compatible with Java and C++ implementations:
ZUS-RS implements params-only compression for requests to match Java's decoder architecture:
This ensures perfect cross-language compatibility:
β
Java Client β Rust Server
β
Rust Client β Java Server
β
C++ Client β Rust Server
β
Rust Client β C++ Server
Single endpoint: tcp://host:port
Multiple endpoints: tcp://host1:port1,host2:port2,host3:port3
Examples:
tcp://localhost:9527tcp://192.168.1.10:9527tcp://service1.example.com:9527,service2.example.com:9527Format: zns://zooserver1:port1[,zooserver2:port2]/service/path/
Examples:
zns://localhost:9528/zus/services/myservice/zns://zoo1:2181,zoo2:2181/zus/services/myservice/zns://10.0.1.1:2181/zus/services/echo/Note: The service path should end with / and correspond to where servers register themselves in ZooServer.
See zus-examples/ for complete examples:
example-client)example-server)example-server-telemetry)Run tests for all feature combinations:
# Test default features
cargo test -p zus-rs
# Test minimal features
cargo test -p zus-rs --no-default-features --features minimal
# Test client only
cargo test -p zus-rs --no-default-features --features client
# Test server only
cargo test -p zus-rs --no-default-features --features server
# Test all features
cargo test -p zus-rs --all-features
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Licensed under either of:
at your option.
Developed by the ZUS Rust Team as a modern, cross-language compatible RPC framework.
Version: 1.1.4 Last Updated: 2026-01-21 Status: Production Ready