// ---------------------------------------------------------------------------- // Examples.MultiTransport.Gateway // // Demonstrates a production-ready API Gateway that supports multiple transports: // - InMemory (development/testing) // - TCP (high-performance internal communication) // - TLS/mTLS (secure communication with certificate auth) // - RabbitMQ (distributed, queue-based messaging) // // The gateway aggregates OpenAPI specs from all connected microservices, // handles routing decisions, authorization, and request dispatch. // ---------------------------------------------------------------------------- using StellaOps.Router.Gateway; using StellaOps.Router.Gateway.Authorization; using StellaOps.Router.Gateway.DependencyInjection; using StellaOps.Router.Config; using StellaOps.Router.Transport.InMemory; var builder = WebApplication.CreateBuilder(args); // ---------------------------------------------------------------------------- // Router Configuration // ---------------------------------------------------------------------------- builder.Services.AddRouterConfig(options => { options.ConfigPath = "router.yaml"; options.EnableHotReload = true; // Hot-reload config changes without restart }); // ---------------------------------------------------------------------------- // Gateway Core Services // ---------------------------------------------------------------------------- builder.Services.AddRouterGateway(builder.Configuration); // ---------------------------------------------------------------------------- // Transport Registration // The gateway accepts connections from microservices using any transport // ---------------------------------------------------------------------------- // InMemory: Zero-latency for local development and testing builder.Services.AddInMemoryTransport(); // Additional transports can be enabled when infrastructure is available: // // TCP: High-performance binary protocol for internal services // builder.Services.AddTcpTransportServer(options => { options.Port = 5100; }); // // TLS: Encrypted communication with optional mutual TLS // builder.Services.AddTlsTransportServer(options => // { // options.Port = 5101; // options.RequireClientCertificate = false; // }); // // RabbitMQ: Distributed messaging for cross-datacenter communication // builder.Services.AddRabbitMqTransportServer(options => // { // options.HostName = "localhost"; // options.Port = 5672; // }); // ---------------------------------------------------------------------------- // Authorization - No-op for demo, integrate with Authority module in production // ---------------------------------------------------------------------------- builder.Services.AddNoOpAuthorityIntegration(); builder.Services.AddAuthentication(); // ---------------------------------------------------------------------------- // OpenAPI / Swagger // ---------------------------------------------------------------------------- builder.Services.AddEndpointsApiExplorer(); var app = builder.Build(); // ---------------------------------------------------------------------------- // Middleware Pipeline // ---------------------------------------------------------------------------- app.UseForwardedHeaders(); app.UseAuthentication(); app.UseClaimsAuthorization(); // Aggregated OpenAPI from all microservices app.MapRouterOpenApi(); // Health and readiness endpoints app.MapGet("/health", () => Results.Ok(new { status = "healthy", timestamp = DateTime.UtcNow })); app.MapGet("/ready", () => Results.Ok(new { ready = true })); // Router gateway - handles all routing decisions and request dispatch app.UseRouterGateway(); Console.WriteLine("Multi-Transport Gateway starting..."); Console.WriteLine("Transports enabled: InMemory (dev)"); Console.WriteLine("Configure additional transports (TCP, TLS, RabbitMQ) as needed"); app.Run(); namespace Examples.MultiTransport.Gateway { public partial class Program { } }