apache / apache/dubbo-rust

Supports Interface Exposure Mode

Open
#182 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
296
Forks
65
PR merge metrics
No merged PRs in 30d

Description

### Supports Interface Exposure Mode, make a webServer ? httpClient like fegin ?

### For Example

### Interface Definition
```rust
#[fusen_trait(package = "org.apache.dubbo.springboot.demo",version = "1.0.0")]
#[resource(method = POST)]
pub trait DemoService {
#[resource(path="/sayHello11",method = POST)]
async fn sayHello(&self, name: String) -> String;

#[resource(path="/sayHelloV22",method = POST)]
async fn sayHelloV2(&self, name: ReqDto) -> ResDto;
}
```

### Server
```rust
#[derive(Clone)]
struct TestServerImpl {
_db: String,
}

#[fusen_server(version="1.0.0")]
#[resource(path="/TestServer",method = POST)]
impl TestServer for TestServerImpl {

#[resource(path="/doRun1",method = POST)]
async fn do_run1(&self, req1: ReqDto, req2: ReqDto) -> FusenResult {
info!("req1 : {:?} , req1 : {:?}", req1, req2);
return Ok(ResDto {
str: "Hello ".to_owned() + &req1.str + " " + &req2.str + " V1",
});
}

#[resource(path="/doRun2",method = POST)]
async fn doRun2(&self, req: ReqDto) -> FusenResult {
info!("res : {:?}", req);
return Ok(ResDto {
str: "Hello ".to_owned() + &req.str + " V2",
});
}
}

#[tokio::main(worker_threads = 512)]
async fn main() {
fusen_common::init_log();
let server: TestServerImpl = TestServerImpl {
_db: "我是一个DB数据库".to_string(),
};
FusenServer::build()
.add_register_builder(RegisterBuilder::new(
&format!("127.0.0.1:{}", "2181"),
"default",
RegisterType::ZooKeeper,
))
.add_protocol(Protocol::HTTP("8082".to_owned()))
.add_protocol(Protocol::HTTP2("8081".to_owned()))
.add_fusen_server(Box::new(server))
.run()
.await;
}
```

### Client
```rust
#[tokio::main(worker_threads = 512)]
async fn main() {
let de = TestServerClient::new(&CLI);
println!("{:?}",de.get_info());
fusen_common::init_log();
let client = de;
let res = client
.do_run1(
ReqDto {
str: "client say hello 1".to_string(),
},
ReqDto {
str: "client say hello 2".to_string(),
},
)
.await;
info!("{:?}", res);
let res = client
.doRun2(ReqDto {
str: "client say hello 2".to_string(),
})
.await;
info!("{:?}", res);
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.