rs2_stream/connectors/
stream_connector.rs1use crate::RS2Stream;
4use async_trait::async_trait;
5use serde::{Deserialize, Serialize};
6use std::time::Duration;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CommonConfig {
11 pub batch_size: usize,
13 pub timeout_ms: u64,
15 pub retry_attempts: usize,
17 pub compression: bool,
19}
20
21impl Default for CommonConfig {
22 fn default() -> Self {
23 Self {
24 batch_size: 100,
25 timeout_ms: 30000,
26 retry_attempts: 3,
27 compression: false,
28 }
29 }
30}
31
32#[async_trait]
34pub trait StreamConnector<T>: Send + Sync
35where
36 T: Send + 'static,
37{
38 type Config: Send + Sync;
40
41 type Error: std::error::Error + Send + Sync + 'static;
43
44 type Metadata: Send + Sync;
46
47 async fn from_source(&self, config: Self::Config) -> Result<RS2Stream<T>, Self::Error>;
49
50 async fn to_sink(
52 &self,
53 stream: RS2Stream<T>,
54 config: Self::Config,
55 ) -> Result<Self::Metadata, Self::Error>;
56
57 async fn health_check(&self) -> Result<bool, Self::Error>;
59
60 async fn metadata(&self) -> Result<Self::Metadata, Self::Error>;
62
63 fn name(&self) -> &'static str;
65
66 fn version(&self) -> &'static str;
68}
69
70#[async_trait]
72pub trait BidirectionalConnector<T>: StreamConnector<T>
73where
74 T: Send + 'static,
75{
76 async fn bidirectional(
78 &self,
79 input_config: Self::Config,
80 output_config: Self::Config,
81 ) -> Result<
82 (
83 RS2Stream<T>,
84 Box<dyn Fn(RS2Stream<T>) -> Result<(), Self::Error> + Send + Sync>,
85 ),
86 Self::Error,
87 >;
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct HealthStatus {
93 pub healthy: bool,
94 pub message: String,
95 pub last_check: Duration,
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct ConnectionStats {
101 pub messages_sent: u64,
102 pub messages_received: u64,
103 pub bytes_sent: u64,
104 pub bytes_received: u64,
105 pub errors: u64,
106 pub uptime: Duration,
107}