-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(transport): Add service multiplexing/routing #99
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f96dab5
feat(transport): Add service multiplexing/routing
LucioFranco 21acdf1
Fix doc tests and clean up docs
LucioFranco dccdad1
Update guides
LucioFranco 4de58b1
Clean up
LucioFranco 981ff6e
Merge remote-tracking branch 'origin/master' into lucio/router
LucioFranco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,37 @@ | ||
pub mod hello_world { | ||
tonic::include_proto!("helloworld"); | ||
} | ||
|
||
pub mod echo { | ||
tonic::include_proto!("grpc.examples.echo"); | ||
} | ||
|
||
use echo::{client::EchoClient, EchoRequest}; | ||
use hello_world::{client::GreeterClient, HelloRequest}; | ||
use tonic::transport::Endpoint; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let channel = Endpoint::from_static("http://[::1]:50051").channel(); | ||
|
||
let mut greeter_client = GreeterClient::new(channel.clone()); | ||
let mut echo_client = EchoClient::new(channel); | ||
|
||
let request = tonic::Request::new(HelloRequest { | ||
name: "Tonic".into(), | ||
}); | ||
|
||
let response = greeter_client.say_hello(request).await?; | ||
|
||
println!("GREETER RESPONSE={:?}", response); | ||
|
||
let request = tonic::Request::new(EchoRequest { | ||
message: "hello".into(), | ||
}); | ||
|
||
let response = echo_client.unary_echo(request).await?; | ||
|
||
println!("ECHO RESPONSE={:?}", response); | ||
|
||
Ok(()) | ||
} |
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,69 @@ | ||
use std::collections::VecDeque; | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
|
||
pub mod hello_world { | ||
tonic::include_proto!("helloworld"); | ||
} | ||
|
||
pub mod echo { | ||
tonic::include_proto!("grpc.examples.echo"); | ||
} | ||
|
||
use hello_world::{ | ||
server::{Greeter, GreeterServer}, | ||
HelloReply, HelloRequest, | ||
}; | ||
|
||
use echo::{ | ||
server::{Echo, EchoServer}, | ||
EchoRequest, EchoResponse, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let addr = "[::1]:50051".parse().unwrap(); | ||
|
||
let greeter = GreeterServer::new(MyGreeter::default()); | ||
let echo = EchoServer::new(MyEcho::default()); | ||
|
||
Server::builder() | ||
.add_service(greeter) | ||
.add_service(echo) | ||
.serve(addr) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct MyGreeter {} | ||
|
||
#[tonic::async_trait] | ||
impl Greeter for MyGreeter { | ||
async fn say_hello( | ||
&self, | ||
request: Request<HelloRequest>, | ||
) -> Result<Response<HelloReply>, Status> { | ||
let reply = hello_world::HelloReply { | ||
message: format!("Hello {}!", request.into_inner().name).into(), | ||
}; | ||
Ok(Response::new(reply)) | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct MyEcho; | ||
|
||
#[tonic::async_trait] | ||
impl Echo for MyEcho { | ||
async fn unary_echo( | ||
&self, | ||
request: Request<EchoRequest>, | ||
) -> Result<Response<EchoResponse>, Status> { | ||
let message = request.into_inner().message; | ||
Ok(Response::new(EchoResponse { message })) | ||
} | ||
|
||
type ServerStreamingEchoStream = VecDeque<Result<EchoResponse, Status>>; | ||
type BidirectionalStreamingEchoStream = VecDeque<Result<EchoResponse, Status>>; | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this supposed to change in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I think it was missed in another PR so I thought i might as well change this now. I want all examples with rustls :)
We really only need openssl for interop since the certs that grpc-go uses are too small for the min that rustls supports.