rest-grpc-multiplex example + tonic-reflection question #1840
-
Hey awesome axum maintainers! I grabbed a copy of the excellent rest-grpc-multiplex example and it works well. When I hook up // snip
let greeter_service = GreeterServer::new(GrpcServiceImpl::default());
let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(proto::FILE_DESCRIPTOR_SET)
.build()
.unwrap();
let grpc = Server::builder()
.add_service(reflection_service)
.add_service(greeter_service)
.into_service(); // <-- type of grpc here is a tower Service router
// the line below works
// let grpc = GreeterServer::new(GrpcServiceImpl::default());
// combine them into one service
let service = MultiplexService::new(rest, grpc);
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(tower::make::Shared::new(service))
.await
.unwrap(); I get the following compiler error: Compiling axum-tonic-multiplex v0.1.0 (/mypathhere/axum-tonic-multiplex)
error[E0271]: type mismatch resolving `<Routes as Service<hyper::Request<hyper::Body>>>::Error == Infallible`
--> src/main.rs:79:10
|
79 | .serve(tower::make::Shared::new(service))
| ^^^^^ expected struct `Box`, found enum `Infallible`
|
= note: expected struct `Box<(dyn std::error::Error + std::marker::Send + Sync + 'static)>`
found enum `Infallible`
note: required for `MultiplexService<axum::Router, Routes>` to implement `Service<hyper::Request<hyper::Body>>`
--> src/multiplex_service.rs:44:12
|
44 | impl<A, B> Service<Request<Body>> for MultiplexService<A, B>
| ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
= note: required for `MultiplexService<axum::Router, Routes>` to implement `hyper::service::http::HttpService<hyper::Body>`
= note: required for `tower::make::Shared<MultiplexService<axum::Router, Routes>>` to implement `hyper::service::make::MakeServiceRef<AddrStream, hyper::Body>`
error[E0277]: the trait bound `hyper::common::exec::Exec: hyper::common::exec::NewSvcExec<AddrStream, SharedFuture<MultiplexService<axum::Router, Routes>>, MultiplexService<axum::Router, Routes>, hyper::common::exec::Exec, hyper::server::server::NoopWatcher>` is not satisfied
--> src/main.rs:80:9
|
80 | .await
| ^^^^^^
| |
| the trait `hyper::common::exec::NewSvcExec<AddrStream, SharedFuture<MultiplexService<axum::Router, Routes>>, MultiplexService<axum::Router, Routes>, hyper::common::exec::Exec, hyper::server::server::NoopWatcher>` is not implemented for `hyper::common::exec::Exec`
| help: remove the `.await`
|
= help: the trait `hyper::common::exec::NewSvcExec<I, N, S, E, W>` is implemented for `hyper::common::exec::Exec`
= note: required for `axum::Server<AddrIncoming, tower::make::Shared<MultiplexService<axum::Router, Routes>>>` to implement `futures::Future`
= note: required for `axum::Server<AddrIncoming, tower::make::Shared<MultiplexService<axum::Router, Routes>>>` to implement `std::future::IntoFuture`
Some errors have detailed explanations: E0271, E0277.
For more information about an error, try `rustc --explain E0271`.
error: could not compile `axum-tonic-multiplex` due to 2 previous errors |
Beta Was this translation helpful? Give feedback.
Answered by
davidpdrsn
Apr 1, 2023
Replies: 1 comment 2 replies
-
If this question belongs in the tonic repo, I'll be happy to post it there as well. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've updated the example to include reflection. See #1902