Expand description
Inter-module RPC communication for distributed method calls 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.0Unless 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.
§Module RPC Communication
This module provides inter-module RPC (Remote Procedure Call) communication capabilities for DMSC, enabling modules to call each other’s methods synchronously or asynchronously.
§Key Components
- DMSCModuleRPC: Main RPC coordinator managing endpoints and method calls
- DMSCModuleClient: Client for making RPC calls to other modules
- DMSCModuleEndpoint: Endpoint definition for a module’s exposed methods
- DMSCMethodCall: Represents an RPC method call request
- DMSCMethodResponse: Represents an RPC method call response
§Design Principles
- Type Safety: All RPC calls are type-safe with proper serialization
- Async Support: Both synchronous and asynchronous RPC calls are supported
- Timeout Control: Configurable timeouts for all RPC calls
- Error Handling: Comprehensive error handling with specific error types
- Thread Safety: All components are thread-safe using Arc and RwLock
- Module Isolation: Each module has its own namespace for methods
§Usage
use dmsc::prelude::*;
async fn example() -> DMSCResult<()> {
// Create RPC coordinator
let rpc = DMSCModuleRPC::new();
// Register a module endpoint
let endpoint = DMSCModuleEndpoint::new("user_service");
endpoint.register_method("get_user", |_params| async {
Ok(vec![b"user_data"])
});
rpc.register_endpoint(endpoint).await;
// Create a client to call methods
let client = DMSCModuleClient::new(rpc.clone());
// Call a method on another module
let response = client.call("user_service", "get_user", vec![]).await?;
println!("Response: {:?}", response);
Ok(())
}Structs§
- DMSC
Method Call - DMSC
Method Registration - DMSC
Method Response - DMSC
Module Client - DMSC
Module Endpoint - DMSC
ModuleRPC