gRPC service with Tonic
Roadster best supports API services using Axum. However, we do provide a gRPC service via a basic integration
with tonic
. Support is pretty minimal and you'll need to manage building
your gRPC Router yourself. However, once it's built, Roadster can take care of running it for you.
fn build_app() -> RoadsterResult<RoadsterApp<AppContext>> {
let app = RoadsterApp::builder()
// Use the default `AppContext` for this example
.state_provider(|context| Ok(context))
// Register the gRPC service with the provided routes
.add_service(GrpcService::new(routes()?))
.build();
Ok(app)
}
/// Build the gRPC [`Router`].
fn routes() -> RoadsterResult<Router> {
let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(hello_world::FILE_DESCRIPTOR_SET)
.build_v1()?;
let router = Server::builder()
.add_service(reflection_service)
.add_service(GreeterServer::new(MyGreeter));
Ok(router)
}