Skip to content
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

Hybrid server with axum+tonic #22

Closed
pixelspark opened this issue Oct 10, 2021 · 10 comments
Closed

Hybrid server with axum+tonic #22

pixelspark opened this issue Oct 10, 2021 · 10 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@pixelspark
Copy link

I am trying to build a hybrid HTTP + gRPC server using Axum and Tonic following this example. I am struggling a bit however on how to combine this with axum-server to have both over TLS:

let app = /* axum app */;
let grpc_service = tonic::transport::Server::builder().add_service(/* some gRPC service */).into_service();
let hybrid_make_service = hybrid(app.into_make_service(), grpc_service);

// This works fine
axum::Server::bind(&sc.bind_address).serve(hybrid_make_service).await?;

// This I can't get right...
axum_server::bind_rustls(sc.bind_address.to_string())
				.private_key_file(tls_key_path)
				.certificate_file(tls_cert_path)
				.serve(hybrid_make_service)
				.await?;

The issue seems to be that axum_server requires a 'Service' whereas the regular 'bind' accepts some sort of 'IntoService' (and the hybrid function, as well as grpc_service, create this). Any ideas?

@pixelspark
Copy link
Author

@programatik29
Copy link
Owner

You need to pass a Service that is Clone.

All Services provided by axum are Clone by default.

RouterService implements Clone if service wrapped in it implements it. So you need to make sure wrapped gRPC service is Clone.

@programatik29 programatik29 added the documentation Improvements or additions to documentation label Oct 10, 2021
@programatik29 programatik29 self-assigned this Oct 10, 2021
@programatik29
Copy link
Owner

I think it is a good idea to add HTTP+gRPC example.

@programatik29
Copy link
Owner

Let me know if this helps.

@pixelspark
Copy link
Author

Let me know if this helps.

Absolutely, this works like a charm! Thanks so much (and indeed, good idea to add this example, should probably end up in this repo?)

@itsyaasir
Copy link

Hey, I am implementing the same http+grpc , and I can see the example has been deleted , can I get it from anywhere ? Thank you

@programatik29
Copy link
Owner

@itsyaasir I removed it because it wasn't up to date. I will write a new example for the new api and let you know when its done.

@itsyaasir
Copy link

@itsyaasir I removed it because it wasn't up to date. I will write a new example for the new api and let you know when its done.

Thank you , I appreciate that

@programatik29
Copy link
Owner

@itsyaasir Let me know if this example works for you.

@itsyaasir
Copy link

@itsyaasir Let me know if this example works for you.

Absolutely, it worked, I got the general idea of the implementation. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants