1 unstable release
Uses new Rust 2024
| 0.1.0 | Jan 24, 2026 |
|---|
#1 in #dubbo
94KB
1.5K
SLoC
Rubbo 🦀🚀
Rubbo is a high-performance, Rust-based RPC framework designed to be fully compatible with the Dubbo 3.0 ecosystem. It leverages the Triple protocol (based on gRPC/HTTP2) and supports seamless interoperability with Java Dubbo applications using Nacos for service discovery.
Features
- Triple Protocol: Fully compatible with Dubbo 3.0 Triple protocol.
- Service Discovery: Built-in support for Nacos registry.
- Macro Support: Easy-to-use attribute macros for defining services and references.
- High Performance: Built on top of
tokioandhyperfor asynchronous I/O. - Interoperability: Works out-of-the-box with Java Dubbo providers and consumers.
- Load Balancing: Pluggable load balancing strategies (default: RoundRobin).
Supported Protocols & Serialization
| Category | Type | Description | Feature Flag |
|---|---|---|---|
| Protocol | Triple | Based on HTTP/2 and gRPC, fully compatible with Dubbo 3.0. | - |
| Serialization | FastJSON | Default text-based JSON serialization. | fastjson (Default) |
| Serialization | FastJSON2 | High-performance binary JSONB format (Dubbo 3 default). | fastjson2 |
| Serialization | Hessian2 | Standard binary serialization. | hessian2 |
Getting Started
Prerequisites
- Rust (latest stable)
- Nacos Server (running on 127.0.0.1:8848 or configurable)
Defining a Service
Define your service interface using the #[rubbo::service] macro:
#[rubbo::service]
trait HelloService {
async fn say_hello(&self, name: String) -> String;
}
Implementing a Provider
Implement the service and start a provider:
use rubbo::{ProviderBuilder, Registry, Protocol, Serialize};
struct HelloServiceImpl;
#[rubbo::service_impl(group = "test_group", version = "1.0.0", name = "com.example.HelloService")]
impl HelloService for HelloServiceImpl {
async fn say_hello(&self, name: String) -> String {
format!("Hello, {}!", name)
}
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
rubbo::ProviderBuilder::new()
.service(HelloServiceImpl)
.application("rubbo-provider-example")
.registry(Registry::Nacos("nacos://127.0.0.1:8848".to_string()))
.protocol(Protocol::Triple)
.serialization(Serialize::Fastjson2)
.port(50051)
.start()
.await?;
Ok(())
}
Implementing a Consumer
Create a consumer to invoke the service:
use rubbo::{ConsumerBuilder, Registry};
#[rubbo::reference(interface_name = "com.example.HelloService", version = "1.0.0", group = "test_group")]
trait HelloService {
async fn say_hello(&self, name: String) -> String;
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let consumer = ConsumerBuilder::new()
.application("rubbo-consumer-example")
.registry(Registry::Nacos("nacos://127.0.0.1:8848".to_string()))
.reference::<dyn HelloService>()
.build()
.await?;
let service = consumer.reference::<dyn HelloService>().await?;
let response = service.say_hello("World".to_string()).await?;
println!("Response: {}", response);
Ok(())
}
Benchmark
We provide a built-in benchmark tool to measure the performance of Rubbo.
Environment
- OS: macOS
- Protocol: Triple (HTTP/2)
- Registry: Nacos (Local)
- Serialization: FastJSON
- Machine: Local Development Machine
Running the Benchmark
- Start Nacos Server (Ensure it's running on port 8848)
- Start the Benchmark Provider:
cargo run --release --example benchmark_provider - Run the Benchmark Consumer:
BENCH_CONCURRENCY=50 BENCH_REQUESTS=20000 cargo run --release --example benchmark_consumer
Results
| Metric | Value |
|---|---|
| Concurrency | 50 threads |
| Total Requests | 20,000 |
| QPS | ~26,384 |
| Avg Latency | 1.88 ms |
| Success Rate | 100% |
Note: Results may vary based on hardware and network conditions.
License
MIT
Dependencies
~14–30MB
~305K SLoC