use std::fmt;
use async_trait::async_trait;
use crate::communication::message::{EncodedMessage, MessageResult};
use crate::communication::tcp_types::ConnectionState;
pub mod message;
pub mod tcp_channel;
pub mod tcp_types;
pub mod ipc;
pub mod ipc_types;
pub mod http_ipc;
pub mod http_tcp;
pub mod ipc_port_negotiation;
pub mod ipc_channel;
pub mod routing;
pub mod failover;
pub mod metrics;
pub mod streaming;
#[async_trait]
pub trait MessageChannel: Send + Sync + fmt::Debug {
async fn send(&self, message: EncodedMessage) -> MessageResult<()>;
async fn receive(&self) -> MessageResult<EncodedMessage>;
async fn state(&self) -> ConnectionState;
async fn connect(&self) -> MessageResult<()>;
async fn disconnect(&self) -> MessageResult<()>;
}
pub use ipc_port_negotiation::PortNegotiationManager;
pub use tcp_channel::TcpChannel;
#[cfg(feature = "ipc_channel")]
pub use ipc_channel::{IpcChannel, IpcConnectionConfig};
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ChannelType {
Tcp,
Ipc,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChannelPreferences {
pub use_tcp: bool,
pub use_ipc: bool,
pub prefer_ipc_for_local: bool,
pub prefer_tcp_for_remote: bool,
pub enable_fallback: bool,
}
impl Default for ChannelPreferences {
fn default() -> Self {
Self {
use_tcp: true,
use_ipc: true,
prefer_ipc_for_local: true,
prefer_tcp_for_remote: true,
enable_fallback: true,
}
}
}
impl ChannelPreferences {
pub fn tcp_only() -> Self {
Self {
use_tcp: true,
use_ipc: false,
prefer_ipc_for_local: false,
prefer_tcp_for_remote: true,
enable_fallback: false,
}
}
pub fn ipc_only() -> Self {
Self {
use_tcp: false,
use_ipc: true,
prefer_ipc_for_local: true,
prefer_tcp_for_remote: false,
enable_fallback: false,
}
}
pub fn prefer_ipc() -> Self {
Self {
use_tcp: true,
use_ipc: true,
prefer_ipc_for_local: true,
prefer_tcp_for_remote: false,
enable_fallback: true,
}
}
pub fn prefer_tcp() -> Self {
Self {
use_tcp: true,
use_ipc: true,
prefer_ipc_for_local: false,
prefer_tcp_for_remote: true,
enable_fallback: true,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ChannelCapabilities {
pub module_messaging: bool,
pub http_proxy: bool,
pub service_calls: bool,
pub file_transfer: bool,
pub streaming: bool,
pub batching: bool,
pub compression: bool,
pub max_message_size: Option<usize>,
}
impl Default for ChannelCapabilities {
fn default() -> Self {
Self {
module_messaging: true,
http_proxy: true,
service_calls: true,
file_transfer: false,
streaming: false,
batching: false,
compression: false,
max_message_size: None,
}
}
}
impl ChannelCapabilities {
pub fn tcp_standard() -> Self {
Self {
module_messaging: true,
http_proxy: true,
service_calls: true,
file_transfer: true,
streaming: true,
batching: true,
compression: true,
max_message_size: Some(64 * 1024 * 1024), }
}
pub fn ipc_standard() -> Self {
Self {
module_messaging: true,
http_proxy: true,
service_calls: true,
file_transfer: true,
streaming: true,
batching: true,
compression: true,
max_message_size: Some(128 * 1024 * 1024), }
}
pub fn high_performance() -> Self {
Self {
module_messaging: true,
http_proxy: true,
service_calls: true,
file_transfer: true,
streaming: true,
batching: true,
compression: true,
max_message_size: Some(1024 * 1024 * 1024), }
}
}
pub use routing::{
ChannelRouter, RoutingConfig, RoutingMatrix, RoutingDecision, MessageCharacteristics,
MessagePriority, MessageType, TargetLocation, ChannelHealth, extract_message_characteristics,
};
pub use failover::{
FailoverManager, FailoverConfig, CircuitBreaker, CircuitBreakerConfig, CircuitBreakerState,
CircuitBreakerStats, RetryMechanism, RetryConfig, MessageBatcher, BatchConfig, MessageBatch,
ConnectionPool, PooledConnection, PoolStats, PerformanceConfig, MessageCompressor,
};
pub use metrics::{
PerformanceMonitoringSystem, ChannelPerformanceTracker, ChannelMetrics, PoolMetrics,
SlaConfig, SlaStatus, ComplianceStatus, AlertConfig, PerformanceAlert, AlertType,
AlertSeverity, PerformanceComparisonReport,
};
pub use streaming::{
StreamConfig, StreamChunk, StreamMetadata, StreamPriority, StreamAck, FlowControlWindow,
StreamSender, StreamReceiver, PubSubMessage, Subscription, PriorityMessageQueue,
RequestMultiplexer,
};