Overview
Contract-first gRPC services from a .proto file, served over HTTP/2 with the same dependency injection and enhancers as every other transport.
ulo-grpc serves gRPC from a .proto file. A build step turns the proto into messages, a client and one marker type per method. Handlers on an ordinary controller bind to those markers, and a dispatcher calls them by path. tonic's generated server trait is never implemented, so there is no *Server::new(handler) step.
The .proto is the contract. A handler whose message types or call shape differ from its marker's fails to compile, with the type it declared beside the type the marker requires.
Crates
| Crate | Role |
|---|---|
ulo-build | build.rs code generation over a vendored protoc: messages, clients and method markers |
ulo-grpc | the transport: Server, #[ulo_grpc::method], status mapping, health, reflection, client modules |
ulo-health-grpc | optional: drives grpc.health.v1 from the application's readiness |
The crate that runs the build step also depends on tonic (features channel and codegen), tonic-prost and prost, because the generated code names them. Rust 1.88 is enough. gRPC runs on tokio, since tonic is tokio-only. An app on another runtime fails listen() at the gRPC server.
How the pieces fit
build.rscompiles the proto withulo_build::configure().compile(..).ulo_grpc::include_proto!("pkg.v1")includes the generated code, markers included.#[ulo_grpc::method(pb::service::Method)]binds a handler to a marker.ulo_grpc::Server::new(addr)serves them. Any gRPC client reaches the result.
gRPC serves on its own port. Nothing routes an application/grpc request that arrives on an HTTP server's port to it.
In this section
- Quick start: a service from proto to a running server (
examples/29-grpc-service). - Call shapes: unary, server-streaming, client-streaming and bidirectional handlers.
- Enhancers: guards, interceptors and error handlers on gRPC.
- Errors and status: kinds to codes and error details.
- Client: a generated client as an ordinary provider, with deadlines forwarded (
examples/30-grpc-client). - Operations: TLS, limits, reflection, health, deadlines and shutdown.
For pattern-routed services without a proto, see Microservices.