-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a3aaad
commit 4f1f762
Showing
8 changed files
with
293 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::{future, net::SocketAddr}; | ||
|
||
use lazy_static::lazy_static; | ||
use volo_thrift::client::CallOpt; | ||
|
||
lazy_static! { | ||
static ref CLIENT: volo_gen::thrift_gen::hello::HelloServiceClient = { | ||
let addr: SocketAddr = "127.0.0.1:8081".parse().unwrap(); | ||
volo_gen::thrift_gen::hello::HelloServiceClientBuilder::new("hello") | ||
.address(addr) | ||
.multiplex(true) | ||
.build() | ||
}; | ||
} | ||
|
||
pub struct LogService<S>(S); | ||
|
||
#[volo::main] | ||
async fn main() { | ||
let subscriber = tracing_subscriber::FmtSubscriber::builder() | ||
.with_max_level(tracing::Level::TRACE) | ||
.finish(); | ||
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); | ||
|
||
let futs = |i| async move { | ||
let req = volo_gen::thrift_gen::hello::HelloRequest { | ||
name: format!("volo{}", i).into(), | ||
}; | ||
let resp = CLIENT | ||
.clone() | ||
.with_callopt(CallOpt::default()) | ||
.hello(req) | ||
.await; | ||
match resp { | ||
Ok(info) => println!("{info:?}"), | ||
Err(e) => eprintln!("{e:?}"), | ||
} | ||
}; | ||
|
||
let mut resps = Vec::with_capacity(10); | ||
for i in 0..resps.capacity() { | ||
resps.push(tokio::spawn(futs(i))); | ||
} | ||
|
||
for resp in resps { | ||
let _ = resp.await; | ||
} | ||
future::pending::<()>().await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::net::SocketAddr; | ||
|
||
pub struct S; | ||
|
||
impl volo_gen::thrift_gen::hello::HelloService for S { | ||
async fn hello( | ||
&self, | ||
req: volo_gen::thrift_gen::hello::HelloRequest, | ||
) -> Result<volo_gen::thrift_gen::hello::HelloResponse, volo_thrift::AnyhowError> { | ||
let resp = volo_gen::thrift_gen::hello::HelloResponse { | ||
message: format!("Hello, {}!", req.name).into(), | ||
}; | ||
Ok(resp) | ||
} | ||
} | ||
|
||
#[volo::main] | ||
async fn main() { | ||
let subscriber = tracing_subscriber::FmtSubscriber::builder() | ||
.with_max_level(tracing::Level::TRACE) | ||
.finish(); | ||
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); | ||
|
||
let addr: SocketAddr = "[::]:8081".parse().unwrap(); | ||
let addr = volo::net::Address::from(addr); | ||
|
||
volo_gen::thrift_gen::hello::HelloServiceServer::new(S) | ||
.multiplex(true) | ||
.run(addr) | ||
.await | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.