đ MsgTrans - Modern Multi-Protocol Communication Framework
đ Language: English | įŽäŊ䏿
Enterprise-grade modern multi-protocol communication framework with unified interface supporting TCP, WebSocket, QUIC and more
đ Core Features
⥠Ultimate Performance
- 1M+ concurrent connections support
- 10M+/sec message throughput
- 1ms average latency
- Lock-free concurrent architecture fully utilizing multi-core performance
đī¸ Unified Architecture Design
- Three-layer architecture abstraction: Application â Transport â Protocol layers with clear separation
- Protocol-agnostic business logic: One codebase, multi-protocol deployment
- Configuration-driven design: Switch protocols through configuration without modifying business logic
- Hot-pluggable extensions: Easily extend new protocol support
⥠Modern Concurrent Architecture
- Lock-free concurrent design: Completely eliminate lock contention, fully utilize multi-core performance
- Zero-copy optimization:
SharedPacket
andArcPacket
implement memory zero-copy - Event-driven model: Fully asynchronous non-blocking, efficient event handling
- Intelligent optimization: CPU-aware automatic performance tuning
đ Multi-Protocol Unified Support
- TCP - Reliable transport protocol
- WebSocket - Real-time Web communication
- QUIC - Next-generation transport protocol
- Custom protocols - Easily implement custom protocol extensions
đ¯ Minimalist API Design
- Builder pattern: Fluent configuration, elegant and readable code
- Type safety: Compile-time error checking, runtime stability and reliability
- Zero-configuration optimization: High performance by default, ready to use out of the box
- Backward compatibility: Zero migration cost for version upgrades
đ Quick Start
Installation
[]
= "1.0.0"
Create Multi-Protocol Server
use ;
async
Create Client Connection
use ;
use Duration;
async
đī¸ Architecture Design
đ Three-Layer Architecture
âââââââââââââââââââââââââââââââââââââââ
â đ¯ Application Layer â â Business logic, protocol-agnostic
âââââââââââââââââââââââââââââââââââââââ¤
â đ Transport Layer â â Connection management, unified API
â âââ TransportServer/Client â âĸ Connection lifecycle management
â âââ SessionManager â âĸ Event routing and dispatching
â âââ EventStream â âĸ Message passing and broadcasting
âââââââââââââââââââââââââââââââââââââââ¤
â đĄ Protocol Layer â â Protocol implementation, extensible
â âââ TCP/WebSocket/QUIC â âĸ Protocol-specific adapters
â âââ ProtocolAdapter â âĸ Protocol configuration management
â âââ ConfigurationRegistry â âĸ Protocol registration mechanism
âââââââââââââââââââââââââââââââââââââââ
đ Design Principles
Unified Abstraction, Protocol Transparency
- TransportServer/Client provide unified business interfaces
- Transport manages single connection lifecycle
- ProtocolAdapter hides protocol implementation details
Configuration-Driven, Flexible Extension
// Same server code, different protocol configurations
let server = new
.with_protocol
.build.await?; // TCP version
let server = new
.with_protocol
.build.await?; // QUIC version - identical business logic
đ¯ Event-Driven Model
// Server event types
// Client event types
// Concise event handling pattern - Server
let mut events = server.events.await?;
while let Some = events.recv.await
// Concise event handling pattern - Client
let mut events = client.events.await?;
while let Some = events.recv.await
⥠Modern Features
đ Lock-Free Concurrent Architecture
// User-level API is simple, underlying automatic lock-free optimization
// Concurrent sending - internally optimized with lock-free queues
let tasks: = .map.collect;
// Server high-concurrency processing - internally using lock-free hash tables for session management
let mut events = server.events.await?;
while let Some = events.recv.await
đ§ Intelligent Optimization
// CPU-aware automatic optimization - zero configuration high performance
let config = auto_optimized; // Auto-tuning based on CPU core count
// Intelligent connection pool - adaptive load
let server = new
.connection_pool_config
.build.await?;
đĻ Zero-Copy Optimization
// User API always simple - internal automatic zero-copy optimization
let result = client.send.await?;
// Large data transmission - automatic zero-copy handling
let large_data = vec!; // 1MB data
let result = client.send.await?;
// Request-response - automatic zero-copy optimization
let response = client.request.await?;
if let Some = response.data
đ Protocol Extension
Implement Custom Protocol
// 1. Implement protocol adapter
// 2. Implement configuration structure
// 3. Seamless integration - exactly the same usage as built-in protocols
let my_config = MyProtocolServerConfig ;
let server = new
.with_protocol // Use directly!
.build
.await?;
đ Usage Examples
đ WebSocket Chat Server
use ;
use HashMap;
async
⥠High-Performance QUIC Client
use ;
use Instant;
async
đ ī¸ Configuration Options
Server Configuration
// TCP Server - High reliability configuration
let tcp_config = new?
.with_max_connections
.with_keepalive
.with_nodelay
.with_reuse_addr;
// WebSocket Server - Web integration configuration
let ws_config = new?
.with_path
.with_max_frame_size
.with_max_connections;
// QUIC Server - Next-generation protocol configuration
let quic_config = new?
.with_cert_path
.with_key_path
.with_alpn
.with_max_concurrent_streams;
Intelligent Configuration
// Zero configuration - automatic optimization (recommended)
let server = new
.with_protocol
.build.await?; // Automatically optimized based on CPU
// High-performance configuration - manual tuning
let server = new
.with_protocol
.connection_config
.max_connections
.build.await?;
// Resource-saving configuration - low memory environment
let server = new
.with_protocol
.connection_config
.max_connections
.build.await?;
đ§ Advanced Features
đ Built-in Monitoring
// Real-time statistics - zero-copy performance monitoring
let stats = server.get_stats.await;
println!;
println!;
println!;
println!;
// Protocol distribution statistics
for in &stats.protocol_distribution
đĄī¸ Graceful Error Handling
use ;
// Message sending error handling
match client.send.await
// Request-response error handling
match client.request.await
// Server-side sending error handling
match server.send.await
đ Connection Management
// Connection pool management
let pool_config = adaptive
.with_initial_size
.with_max_size
.with_idle_timeout
.with_health_check_interval;
// Graceful shutdown
let server = new
.with_protocol
.graceful_shutdown_timeout
.build.await?;
// Smooth restart support
server.start_graceful_shutdown.await?;
đ Documentation and Examples
đ Complete Examples
Check the examples/
directory for more examples:
echo_server.rs
- Multi-protocol echo serverecho_client_tcp.rs
- TCP client exampleecho_client_websocket.rs
- WebSocket client exampleecho_client_quic.rs
- QUIC client examplepacket.rs
- Packet serialization verification example
đ Running Examples
# Start multi-protocol echo server
# Test TCP client
# Test WebSocket client
# Test QUIC client
đ Use Cases
- đŽ Game Servers - High-concurrency real-time game communication
- đŦ Chat Systems - Multi-protocol instant messaging platforms
- đ Microservice Communication - Efficient inter-service data transmission
- đ Real-time Data - Financial, monitoring and other real-time systems
- đ IoT Platforms - Large-scale device connection management
- đĒ Protocol Gateways - Multi-protocol conversion and proxying
đ License
This project is licensed under the Apache License 2.0.
Copyright Š 2024 Jiaqing Zou
đ¤ Contributing
Issues and Pull Requests are welcome! Please check the Contributing Guide for detailed information.
đ¯ MsgTrans Mission: Make multi-protocol communication simple, efficient, and reliable, focusing on business logic rather than underlying transport details.