-
Notifications
You must be signed in to change notification settings - Fork 1
/
echo-srv.rs
37 lines (32 loc) · 973 Bytes
/
echo-srv.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::sync::Arc;
use axum_grpc_consul::pb;
#[tokio::main]
async fn main() {
let addr = "127.0.0.1:19527";
let echo = EchoService {
prefix: Arc::new("【小猪佩奇】".to_string()),
};
println!("EchoServer 监听于 {}", addr);
tonic::transport::Server::builder()
.add_service(pb::echo_serivce_server::EchoSerivceServer::new(echo))
.serve(addr.parse().unwrap())
.await
.unwrap();
}
pub struct EchoService {
pub prefix: Arc<String>,
}
#[tonic::async_trait]
impl pb::echo_serivce_server::EchoSerivce for EchoService {
async fn echo(
&self,
request: tonic::Request<pb::EchoRequest>,
) -> Result<tonic::Response<pb::EchoResponse>, tonic::Status> {
let pb::EchoRequest { message } = request.into_inner();
let resp = pb::EchoResponse {
message,
prefix: Some(self.prefix.to_string()),
};
Ok(tonic::Response::new(resp))
}
}