Module service_mesh

Module service_mesh 

Source
Expand description

Service discovery and traffic management Copyright © 2025-2026 Wenze Wei. All Rights Reserved.

This file is part of DMSC. The DMSC project belongs to the Dunimd Team.

Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

§Service Mesh Module

This module provides a comprehensive service mesh implementation for DMSC, offering service discovery, health checking, traffic management, load balancing, and circuit breaking capabilities for distributed systems.

§Key Components

  • DMSCServiceMesh: Main service mesh struct implementing the DMSCModule trait
  • DMSCServiceMeshConfig: Configuration for service mesh behavior
  • DMSCServiceEndpoint: Service endpoint representation
  • DMSCServiceHealthStatus: Enum defining service health statuses
  • DMSCServiceDiscovery: Service discovery component
  • DMSCServiceInstance: Service instance representation
  • DMSCServiceStatus: Service status enum
  • DMSCHealthChecker: Health checking component
  • DMSCHealthCheckResult: Health check result structure
  • DMSCHealthSummary: Health summary structure
  • DMSCHealthStatus: Health status enum
  • DMSCTrafficManager: Traffic management component
  • DMSCTrafficRoute: Traffic route definition
  • DMSCMatchCriteria: Match criteria for traffic routing
  • DMSCRouteAction: Route action for traffic routing
  • DMSCCircuitBreaker: Circuit breaker for preventing cascading failures
  • DMSCLoadBalancer: Load balancer for distributing traffic across services
  • DMSCLoadBalancerStrategy: Load balancing strategies

§Design Principles

  1. Service Discovery: Automatic discovery of services and their endpoints
  2. Health Monitoring: Continuous health checks for service endpoints
  3. Traffic Management: Intelligent routing and load balancing of traffic
  4. Resilience: Circuit breaking and retry mechanisms for service resilience
  5. Configurable: Highly configurable service mesh behavior
  6. Async-First: All service mesh operations are asynchronous
  7. Modular Design: Separate components for service discovery, health checking, and traffic management
  8. Service Module Integration: Implements DMSCModule trait for seamless integration into DMSC
  9. Thread-safe: Uses Arc and RwLock for safe concurrent access
  10. Critical Component: Marked as critical for the system’s operation

§Usage

use dmsc::prelude::*;
use dmsc::service_mesh::{DMSCServiceMesh, DMSCServiceMeshConfig};
 
async fn example() -> DMSCResult<()> {
    // Create service mesh configuration
    let mesh_config = DMSCServiceMeshConfig::default();
     
    // Create service mesh instance
    let service_mesh = DMSCServiceMesh::new(mesh_config)?;
     
    // Register services
    service_mesh.register_service("user-service", "http://user-service:8080", 100).await?;
    service_mesh.register_service("order-service", "http://order-service:8080", 100).await?;
    service_mesh.register_service("payment-service", "http://payment-service:8080", 100).await?;
     
    // Discover services
    let user_service_endpoints = service_mesh.discover_service("user-service").await?;
    println!("User service endpoints: {:?}", user_service_endpoints);
     
    // Call a service
    let request_data = r#"{ "user_id": "123" }"#.as_bytes().to_vec();
    let response = service_mesh.call_service("user-service", request_data).await?;
    println!("Service response: {}", String::from_utf8_lossy(&response));
     
    // Get service mesh components for advanced configuration
    let health_checker = service_mesh.get_health_checker();
    let traffic_manager = service_mesh.get_traffic_manager();
    let circuit_breaker = service_mesh.get_circuit_breaker();
    let load_balancer = service_mesh.get_load_balancer();
     
    // Example: Configure traffic manager
    // traffic_manager.add_route(route).await?;
     
    Ok(())
}

Re-exports§

pub use service_discovery::DMSCServiceDiscovery;
pub use service_discovery::DMSCServiceInstance;
pub use service_discovery::DMSCServiceStatus;
pub use health_check::DMSCHealthChecker;
pub use health_check::DMSCHealthCheckResult;
pub use health_check::DMSCHealthSummary;
pub use health_check::DMSCHealthStatus;
pub use traffic_management::DMSCTrafficRoute;
pub use traffic_management::DMSCMatchCriteria;
pub use traffic_management::DMSCRouteAction;
pub use traffic_management::DMSCWeightedDestination;
pub use traffic_management::DMSCTrafficManager;

Modules§

health_check
Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
service_discovery
Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
traffic_management
Copyright © 2025-2026 Wenze Wei. All Rights Reserved.

Structs§

DMSCServiceEndpoint
Service endpoint representation.
DMSCServiceMesh
Main service mesh struct implementing the DMSCModule trait.
DMSCServiceMeshConfig
Configuration for the service mesh.
DMSCServiceMeshStats
Service mesh statistics.

Enums§

DMSCServiceHealthStatus
Service health status enum.