pub struct GrpcServer { /* private fields */ }Expand description
A gRPC server.
Allows serving multiple gRPC services from a single endpoint.
This type is a thin wrapper over helper types from tonic and axum, and principally is meant to provide an opaque
gRPC server implementation that operates correctly when run under supervision. As such, this type can’t be manually
served: it is only usable by adding it to a supervisor.
§Supervision
The listen address is bound during initialization, so a failure to bind is raised before the supervised worker starts running, and a restart rebinds.
The server will attempt to gracefully shutdown existing connections when the parent supervisor signals shutdown. This will cause the worker to utilize the maximum allowable grace period during shutdown: it will attempt to take as long as necessary to gracefully shutdown existing connections, bounded only by the parent supervisor.
Implementations§
Source§impl GrpcServer
impl GrpcServer
Sourcepub fn new(listen_addr: ListenAddress) -> Self
pub fn new(listen_addr: ListenAddress) -> Self
Creates an empty server with no attached services, configured to listen on the given address.
Sourcepub fn with_graceful_shutdown_timeout(self, timeout: Duration) -> Self
pub fn with_graceful_shutdown_timeout(self, timeout: Duration) -> Self
Sets the graceful shutdown timeout for this server.
During shutdown, the server will for all in-flight connections to complete before ultimately completing itself. When no timeout is specified, this will lead to the worker taking the maximum allowable time to shutdown if connections are blocked or otherwise “stuck.” Setting an explicit graceful shutdown timeout will cause the worker to bound how long it waits for in-flight connections to shutdown before forcefully completing and moving on.
Defaults to no timeout (wait as long as allowed).
Sourcepub fn add_service<S>(self, svc: S) -> Selfwhere
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + Sync + 'static,
S::Response: IntoResponse,
S::Future: Send + 'static,
pub fn add_service<S>(self, svc: S) -> Selfwhere
S: Service<Request<Body>, Error = Infallible> + NamedService + Clone + Send + Sync + 'static,
S::Response: IntoResponse,
S::Future: Send + 'static,
Adds a new service to this server.
Trait Implementations§
Source§impl Supervisable for GrpcServer
impl Supervisable for GrpcServer
Source§fn shutdown_strategy(&self) -> ShutdownStrategy
fn shutdown_strategy(&self) -> ShutdownStrategy
Source§fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl Freeze for GrpcServer
impl !RefUnwindSafe for GrpcServer
impl Send for GrpcServer
impl Sync for GrpcServer
impl Unpin for GrpcServer
impl !UnwindSafe for GrpcServer
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
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::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read moreSource§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read more