feat(transport): Add service multiplexing/routing#99
Conversation
This change introduces a new "router" built on top of
`transport::Server` that allows one to run multiple
gRPC services on the same socket.
```rust
Server::builder()
.add_service(greeter)
.add_service(echo)
.serve(addr)
.await?;
```
There is also a new `multiplex` example showcasing
server side service multiplexing and client side
service multiplexing.
BREAKING CHANGES: `Server::serve` is now crate private
and all services must be added via `Server::add_service`.
Codegen also returns just a `Service` now instead of a
`MakeService` pair.
Closes #29
Signed-off-by: Lucio Franco luciofranco14@gmail.com
| let client_identity = Identity::from_pem(client_cert, client_key); | ||
|
|
||
| let tls = ClientTlsConfig::with_openssl() | ||
| let tls = ClientTlsConfig::with_rustls() |
There was a problem hiding this comment.
Was this supposed to change in this PR?
There was a problem hiding this comment.
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.
| /// | ||
| /// This will clone the `Server` builder and create a router that will | ||
| /// route around different services. | ||
| pub fn add_service<S>(&mut self, svc: S) -> Router<S, Unimplemented> |
There was a problem hiding this comment.
Why does this need to take &mut self if it immediately clones self?
There was a problem hiding this comment.
Because you can create multiple routers from one Server config was the idea. It takes a &mut because it follows like the others.
| Ok(()).into() | ||
| } | ||
|
|
||
| fn call(&mut self, _req: Request<Body>) -> Self::Future { |
There was a problem hiding this comment.
do you think this should record a tracing event as well? that way, users get some visibility into when requests hit the unimplemented route (in logs, metrics, etc...)
There was a problem hiding this comment.
Ummm probably a good idea, but I'd like to add tracing in another PR.
| impl<A, B, Request> Routes<A, B, Request> { | ||
| pub(crate) fn push<C>( | ||
| self, | ||
| predicate: impl Fn(&Request) -> bool + Send + Sync + 'static, |
There was a problem hiding this comment.
It might be worth considering a Predicate trait so that users can add more complex filtering? Probably not in this branch though.
There was a problem hiding this comment.
Yeah, once we get a stable release of tokio, im gonna update a bunch of the tower services and will impl this there.
* feat(transport): Add service multiplexing/routing
This change introduces a new "router" built on top of
`transport::Server` that allows one to run multiple
gRPC services on the same socket.
```rust
Server::builder()
.add_service(greeter)
.add_service(echo)
.serve(addr)
.await?;
```
There is also a new `multiplex` example showcasing
server side service multiplexing and client side
service multiplexing.
BREAKING CHANGES: `Server::serve` is now crate private
and all services must be added via `Server::add_service`.
Codegen also returns just a `Service` now instead of a
`MakeService` pair.
Closes hyperium#29
Signed-off-by: Lucio Franco luciofranco14@gmail.com
This change introduces a new "router" built on top of
transport::Serverthat allows one to run multiplegRPC services on the same socket.
Example
There is also a new
multiplexexample showcasingserver side service multiplexing and client side
service multiplexing.
BREAKING CHANGES:
Server::serveis now crate privateand all services must be added via
Server::add_service.Codegen also returns just a
Servicenow instead of aMakeServicepair.Closes #29
cc @rlabrecque @seanmonstar @carllerche
Signed-off-by: Lucio Franco luciofranco14@gmail.com