Skip to main content

crabka_grpc_gateway/
lib.rs

1//! `crabka-grpc-gateway` — gRPC / Connect-RPC + HTTP gateway into Crabka topics.
2//!
3//! Built on the native client crates. The broker's Kafka wire stays byte-exact;
4//! the gateway translates Connect-RPC calls into producer, consumer, schema,
5//! deduplication, and authorization operations.
6//!
7//! ## Serving the gateway
8//!
9//! ```no_run
10//! use axum::Router;
11//! use crabka_grpc_gateway::{router, state::AppState};
12//! use std::sync::Arc;
13//!
14//! # async fn run(state: Arc<AppState>) -> Result<(), Box<dyn std::error::Error>> {
15//! let app: Router = router(state);
16//! let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
17//! axum::serve(listener, app).await?;
18//! # Ok(())
19//! # }
20//! ```
21
22pub mod authz;
23pub mod codec;
24pub mod config;
25pub mod consume;
26pub mod dedup;
27pub mod error;
28pub mod forward;
29pub mod handlers;
30pub mod health;
31pub mod metrics;
32pub mod outbound;
33pub mod outbound_config;
34pub mod produce;
35pub mod schema;
36pub mod serve;
37pub mod state;
38pub mod streaming;
39pub mod types;
40pub mod webhook;
41pub mod webhook_config;
42
43/// Build the Connect-RPC [`axum::Router`] for the Gateway service.
44///
45/// The returned router has the shared `AppState` wired in as an
46/// `Extension` layer so each handler can extract it with
47/// `axum::Extension<Arc<AppState>>`.
48pub fn router(state: std::sync::Arc<state::AppState>) -> axum::Router {
49    pb::gateway_connect::GatewayServiceBuilder::<()>::new()
50        .send(handlers::send)
51        .send_stream(streaming::send_stream)
52        .subscribe(streaming::subscribe)
53        .build()
54        .layer(axum::Extension(state))
55}
56
57/// Generated protobuf + Connect server stubs. The actual content lives
58/// in `OUT_DIR/crabka.gateway.v1.rs` and is produced by `build.rs`.
59///
60/// Pedantic lints are silenced here because the include is verbatim
61/// codegen output; we cannot retrofit `#[must_use]` annotations or
62/// shorter helper functions without forking the upstream codegen.
63#[allow(clippy::pedantic, clippy::style)]
64pub mod pb {
65    include!(concat!(env!("OUT_DIR"), "/crabka.gateway.v1.rs"));
66}