sunbeam-g2v
A ConnectRPC-based framework for building microservices in Rust.
Features
- Service trait —
SunbeamServicewithon_start/on_stophooks and graceful shutdown - Configuration — Figment-based config with env-var support via
ServiceConfig - Server builders —
ServerBuilder→AxumServer(orStandaloneServer) with one-shotserve() - Middleware stack — JWT validation, Keto authorization, Prometheus metrics, request IDs, logging, tracing, panic recovery
- Database — SQLx Postgres integration with
connect/connect_eagerand automatic migrations - Message queue — NATS / JetStream wrapper (
NatsClient) with stream and consumer helpers - Leader election — Pluggable
LeaderElectiontrait with Vault and NATS implementations - Client resiliency —
ClientFactory,RetryLayer/RetryPolicy, and a fullCircuitBreaker - Health checks —
HealthRouterexposing/health/liveand/health/ready - Testing —
TestHarness(boots a real server on a random port),MockService, data fixtures - Proc-macros —
#[derive(Instrumented)]and#[derive(Metrics)]
Quick start
use *;
async
See the examples/ directory for a complete working service with JWT, Keto, and health checks.
Architecture
flowchart LR
A["ServerBuilder"] --> B["with_router"]
B --> C["with_health"]
C --> D["with_config"]
D --> E["build_axum"]
E --> F["AxumServer"]
F --> G["serve"]
graph TB
subgraph Middleware
direction LR
H["RequestIdLayer"] --> I["JwtLayer"]
I --> J["KetoLayer"]
J --> K["InstrumentationLayer"]
K --> L["LoggingLayer"]
L --> M["TracingLayer"]
M --> N["CatchPanicLayer"]
end
Feature flags
| Feature | Description |
|---|---|
axum |
Axum server integration (default) |
standalone |
Hyper standalone server |
sqlx / sqlx-postgres |
Database connectivity |
nats |
NATS / JetStream messaging |
redis |
Redis client |
jwt |
JWT validation middleware |
keto |
Ory Keto authorization |
vault |
HashiCorp Vault integration |
election |
Leader election (requires vault + nats) |
metrics |
Prometheus metrics |
tracing |
OpenTelemetry tracing |
logging |
tracing-subscriber logging |
tls |
TLS support |
all |
Every feature listed above |
Default features enable: axum, metrics, tracing, logging, sqlx, sqlx-postgres, nats, jwt, keto, vault, election.
Minimal dependencies
[]
= { = "0.2", = false, = ["axum", "metrics", "jwt"] }
API Reference
Full API docs are published to docs.rs/sunbeam-g2v.
License
MIT