autumn_plugin_grpc/lib.rs
1//! gRPC for [Autumn](https://autumn-web.app), built on
2//! [tonic](https://docs.rs/tonic).
3//!
4//! ```rust,ignore
5//! use autumn_plugin_grpc::GrpcPlugin;
6//!
7//! #[autumn_web::main]
8//! async fn main() {
9//! autumn_web::app()
10//! .routes(routes![index])
11//! .plugin(GrpcPlugin::new().add_service(GreeterServer::new(MyGreeter)))
12//! .run()
13//! .await;
14//! }
15//! ```
16//!
17//! The plugin runs a dedicated HTTP/2 listener (default `0.0.0.0:50051`).
18//! With the `multiplex` feature and `listener = "shared"`, it uses
19//! Autumn's HTTP port instead. It adds:
20//!
21//! - the standard health service `grpc.health.v1.Health`,
22//! - server reflection (on in `dev`/`test`),
23//! - a `grpc` indicator in `/actuator/health`,
24//! - `grpc_server_*` metrics in `/actuator/prometheus`,
25//! - `AppState` in each request's extensions,
26//! - graceful drain on shutdown.
27//!
28//! With the `client` feature, handlers call other gRPC services with
29//! `GrpcClient` and `GrpcClients` (`[grpc.clients.<name>]`).
30//!
31//! See [`GrpcConfig`] for the `[grpc]` section of `autumn.toml`.
32
33#![forbid(unsafe_code)]
34
35#[cfg(feature = "client")]
36mod client;
37mod config;
38mod error;
39mod gate;
40mod health;
41mod lifecycle;
42mod metrics;
43mod plugin;
44mod registry;
45mod server;
46mod timeout;
47mod tls;
48
49#[cfg(feature = "client")]
50pub use client::{
51 ClientError, GrpcChannel, GrpcClient, GrpcClients, GrpcResultExt, http_status, status_to_error,
52};
53pub use config::{
54 ClientConfig, ClientTls, ConfigError, DEFAULT_SECTION, GrpcConfig, Listener, Resolved,
55 TlsConfig, Toggle,
56};
57pub use error::GrpcError;
58pub use lifecycle::{Lifecycle, LifecycleCell, LifecycleEvent};
59pub use plugin::{GrpcPlugin, PLUGIN_NAME, SUPPORTED_AUTUMN_WEB};
60pub use registry::GrpcServers;
61pub use server::GrpcHandle;
62
63/// Re-exports, so apps use the same tonic version as the plugin.
64pub use tonic;
65pub use tonic_health;
66pub use tonic_reflection;