sunbeam-g2v 0.1.1

Sunbeam Service Framework - A ConnectRPC-based framework for building microservices
Documentation

sunbeam-g2v

A ConnectRPC-based framework for building microservices in Rust.

Features

  • Service traitSunbeamService with on_start/on_stop hooks and graceful shutdown
  • Configuration – Figment-based config with env-var support via ServiceConfig
  • Server buildersServerBuilderAxumServer (or StandaloneServer) with one-shot serve()
  • Middleware stack – JWT validation, Keto authorization, Prometheus metrics, request IDs, logging, tracing, panic recovery
  • Database – SQLx Postgres integration with connect/connect_eager and automatic migrations
  • Message queue – NATS / JetStream wrapper (NatsClient) with stream and consumer helpers
  • Leader election – Pluggable LeaderElection trait with Vault and NATS implementations
  • Client resiliencyClientFactory, RetryLayer/RetryPolicy, and a full CircuitBreaker
  • Health checksHealthRouter exposing /health/live and /health/ready
  • TestingTestHarness (boots a real server on a random port), MockService, data fixtures
  • Proc-macros#[derive(Instrumented)] and #[derive(Metrics)]

Quick start

[dependencies]
sunbeam-g2v = "0.1.0"
use sunbeam_g2v::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    let router = ServiceRouter::new();
    ServerBuilder::new()
        .with_router(router)
        .serve()
        .await
}

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