pub struct GrpcServerBuilder { /* private fields */ }Expand description
Builder for a GrpcServer component.
§gRPC Reflection
Enable server reflection so tools like grpcurl can discover services:
// In your build.rs, configure tonic_build to output a file descriptor set:
// tonic_build::configure()
// .file_descriptor_set_path("src/descriptor.bin")
// .compile(&["proto/my_service.proto"], &["proto/"])?;
let descriptor = include_bytes!("descriptor.bin");
let server = GrpcServerBuilder::new(GrpcServerConfig::default())
.with_reflection(descriptor)
.build();Then query with grpcurl:
grpcurl -plaintext localhost:50051 list
grpcurl -plaintext localhost:50051 describe my.package.MyServiceImplementations§
Source§impl GrpcServerBuilder
impl GrpcServerBuilder
Sourcepub fn new(config: GrpcServerConfig) -> Self
pub fn new(config: GrpcServerConfig) -> Self
Create a new builder with the given server configuration.
Sourcepub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Override the component name (default: "grpc-server").
Sourcepub fn with_reflection(self, file_descriptor_set: &[u8]) -> Self
pub fn with_reflection(self, file_descriptor_set: &[u8]) -> Self
Enable gRPC server reflection for service discovery.
Accepts the compiled FileDescriptorSet bytes produced by tonic-build.
Configure tonic-build in your build.rs:
tonic_build::configure()
.file_descriptor_set_path("src/descriptor.bin")
.compile(&["proto/service.proto"], &["proto/"])?;Then pass the bytes to the builder:
builder.with_reflection(include_bytes!("descriptor.bin"))Sourcepub fn add_service<S>(self, svc: S) -> Self
pub fn add_service<S>(self, svc: S) -> Self
Add a tonic-generated service.
The service is automatically wrapped with ErrorLayer so that all
gRPC error responses carry structured JSON details. If
with_reflection was called, the reflection
service is automatically added alongside each user service.
Sourcepub fn build(self) -> GrpcServer
pub fn build(self) -> GrpcServer
Build the GrpcServer component.
Only the last registered service is used for the actual server (since
tonic::transport::Router can’t be accumulated type-safely without the
concrete service type). For multiple services, compose them before calling
add_service, or use the raw tonic API.
Auto Trait Implementations§
impl !RefUnwindSafe for GrpcServerBuilder
impl !UnwindSafe for GrpcServerBuilder
impl Freeze for GrpcServerBuilder
impl Send for GrpcServerBuilder
impl Sync for GrpcServerBuilder
impl Unpin for GrpcServerBuilder
impl UnsafeUnpin for GrpcServerBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request