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
[]
= "0.1.0"
use *;
async
See the examples/ directory for a complete working service with JWT, Keto, and health checks.
Architecture
Application
│
▼
ServerBuilder ──▶ AxumServer ──▶ axum::serve
│
▼
Middleware Stack
JwtLayer → KetoLayer → InstrumentationLayer → RequestIdLayer → LoggingLayer
│
▼
Abstractions
SunbeamService │ ServiceRouter │ ServiceError │ ServiceConfig
│
├──▶ DB (sqlx)
├──▶ MQ (NATS)
├──▶ Election (Vault / NATS)
├──▶ Client (Retry + CircuitBreaker)
└──▶ Health (HealthRouter)
Feature flags
| Feature | Description |
|---|---|
axum |
Axum server integration (default) |
standalone |
Hyper standalone server |
sqlx / sqlx-postgres |
Database connectivity |
nats |
NATS / JetStream messaging |
jwt |
JWT validation middleware |
keto |
Ory Keto authorization |
vault |
HashiCorp Vault integration |
election |
Leader election (requires vault + nats) |
metrics |
Prometheus metrics |
tracing |
OpenTelemetry tracing |
License
MIT