revoke 0.3.0

High-performance microservices infrastructure framework built with pure Rust
Documentation
# Revoke Framework

[![Crates.io](https://img.shields.io/crates/v/revoke.svg)](https://crates.io/crates/revoke)
[![Documentation](https://docs.rs/revoke/badge.svg)](https://docs.rs/revoke)
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](LICENSE)

A high-performance microservices infrastructure framework built with pure Rust, providing comprehensive components for building distributed systems.

## Features

- πŸš€ **High Performance**: Built on async Rust with minimal overhead
- 🌐 **API Gateway**: Powered by Cloudflare Pingora for exceptional performance
- πŸ” **Service Discovery**: Dynamic service registration and discovery
- βš™οΈ **Configuration Management**: Centralized configuration with hot-reloading
- πŸ“Š **Distributed Tracing**: OpenTelemetry integration for observability
- πŸ“¨ **Message Queue**: Unified interface for various MQ systems
- πŸ›‘οΈ **Resilience**: Circuit breakers, rate limiting, and retry mechanisms
- πŸ¦€ **Pure Rust**: No external system dependencies, just Rust

## Quick Start

Add `revoke` to your `Cargo.toml`:

```toml
[dependencies]
revoke = "0.1"
tokio = { version = "1", features = ["full"] }
```

### Basic Example

```rust
use revoke::prelude::*;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create service registry
    let registry = Arc::new(MemoryRegistry::new());
    
    // Register a service
    let service = ServiceInfo {
        id: uuid::Uuid::new_v4(),
        name: "user-service".to_string(),
        version: "1.0.0".to_string(),
        address: "127.0.0.1".to_string(),
        port: 3000,
        protocol: Protocol::Http,
        metadata: Default::default(),
    };
    registry.register(service).await?;
    
    // Query services
    let services = registry.get_service("user-service").await?;
    println!("Found {} instances of user-service", services.len());
    
    Ok(())
}
```

## Feature Flags

### Individual Components

- `gateway` - API gateway with load balancing
- `registry` - Service registry and discovery
- `config` - Configuration management
- `trace` - Distributed tracing
- `mq` - Message queue abstractions
- `resilience` - Circuit breakers and resilience patterns

### Feature Combinations

- `default` = `full` - All features enabled
- `minimal` - Only core functionality
- `service-mesh` - Gateway + Registry + Config + Trace
- `messaging` - Message Queue + Config
- `reliability` - Resilience + Registry

### Usage Examples

Only core functionality:
```toml
revoke = { version = "0.1", default-features = false }
```

Service mesh components:
```toml
revoke = { version = "0.1", default-features = false, features = ["service-mesh"] }
```

Custom selection:
```toml
revoke = { version = "0.1", default-features = false, features = ["gateway", "registry"] }
```

## Components

### API Gateway

High-performance API gateway built on Pingora:

```rust
use revoke::prelude::*;
use revoke::gateway::RevokeGateway;

let config = GatewayConfig {
    bind: "0.0.0.0:8080".to_string(),
    workers: 4,
    log_level: "info".to_string(),
    enable_health_check: true,
    health_check_interval: 10,
    backend_refresh_interval: 30,
};

let gateway = RevokeGateway::new(registry)?;
gateway.run(config)?;
```

### Service Registry

Dynamic service discovery with health checking:

```rust
// Memory registry for development
let registry = Arc::new(MemoryRegistry::new());

// Consul registry for production
let consul_config = ConsulConfig::builder()
    .address("http://localhost:8500")
    .build()?;
let registry = Arc::new(ConsulRegistry::new(consul_config).await?);
```

### Configuration Management

Centralized configuration with hot-reloading:

```rust
use revoke::config::{ConfigProvider, memory::MemoryConfigProvider};

let config = Arc::new(MemoryConfigProvider::new());
config.set("database.url", "postgres://localhost/mydb").await?;

let db_url = config.get("database.url").await?;
```

### Circuit Breaker

Protect against cascading failures:

```rust
use revoke::resilience::{CircuitBreaker, CircuitBreakerBuilder};

let breaker = CircuitBreakerBuilder::new()
    .failure_threshold(5)
    .success_threshold(2)
    .timeout(Duration::from_secs(60))
    .build();

let result = breaker.call(async {
    // Your potentially failing operation
    risky_operation().await
}).await?;
```

### Rate Limiter

Control request rates:

```rust
use revoke::resilience::{RateLimiter, RateLimiterBuilder};

let limiter = RateLimiterBuilder::new()
    .requests_per_second(100.0)
    .burst_size(200)
    .build();

if limiter.check_key("user-123").await? {
    // Process request
} else {
    // Rate limit exceeded
}
```

## Complete Example

Here's a complete microservice setup:

```rust
use revoke::prelude::*;
use revoke::gateway::RevokeGateway;
use revoke::resilience::{CircuitBreaker, RateLimiter};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize components
    let registry = Arc::new(MemoryRegistry::new());
    let config = Arc::new(MemoryConfigProvider::new());
    
    // Configure rate limiter
    let rate_limiter = RateLimiterBuilder::new()
        .requests_per_second(1000.0)
        .build();
    
    // Configure circuit breaker
    let circuit_breaker = CircuitBreakerBuilder::new()
        .failure_threshold(5)
        .build();
    
    // Register services
    for i in 0..3 {
        let service = ServiceInfo {
            id: uuid::Uuid::new_v4(),
            name: "api-service".to_string(),
            version: "1.0.0".to_string(),
            address: "127.0.0.1".to_string(),
            port: 3000 + i,
            protocol: Protocol::Http,
            metadata: Default::default(),
        };
        registry.register(service).await?;
    }
    
    // Start gateway
    let gateway_config = GatewayConfig {
        bind: "0.0.0.0:8080".to_string(),
        workers: 4,
        log_level: "info".to_string(),
        enable_health_check: true,
        health_check_interval: 10,
        backend_refresh_interval: 30,
    };
    
    let gateway = RevokeGateway::new(registry.clone())?;
    
    println!("Starting Revoke gateway on {}", gateway_config.bind);
    gateway.run(gateway_config)?;
    
    Ok(())
}
```

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   API Gateway   │────▢│ Service Registry│◀────│   Microservice  β”‚
β”‚   (Pingora)     β”‚     β”‚  (Consul/Memory)β”‚     β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                        β”‚
         β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚
         └─────────────▢│ Config Provider β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚  (Consul/Memory)β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Performance

Revoke is designed for high performance:

- Zero-copy message passing where possible
- Async/await throughout for optimal concurrency
- Connection pooling and reuse
- Efficient serialization with serde
- Minimal allocations in hot paths

## Contributing

Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.

## License

This project is licensed under either of

- Apache License, Version 2.0, ([LICENSE-APACHE]LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT]LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

## Acknowledgments

- Built on [Pingora]https://github.com/cloudflare/pingora by Cloudflare
- Inspired by Spring Cloud and other microservice frameworks
- Thanks to the Rust async ecosystem