open_feature_flagd/resolver/in_process/storage/connector/mod.rs
1pub mod file;
2pub mod grpc;
3
4pub use file::FileConnector;
5pub use grpc::GrpcStreamConnector;
6
7use std::collections::HashMap;
8use std::sync::Arc;
9use tokio::sync::Mutex;
10use tokio::sync::mpsc::Receiver;
11
12/// Payload sent through the connector stream containing flag data or errors
13#[derive(Debug, Clone)]
14pub struct QueuePayload {
15 /// Type of payload (Data or Error)
16 pub payload_type: QueuePayloadType,
17 /// Flag configuration data (JSON string) or error message
18 pub flag_data: String,
19 /// Optional metadata associated with the sync
20 pub metadata: Option<HashMap<String, serde_json::Value>>,
21}
22
23/// Type of payload in the queue
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
25pub enum QueuePayloadType {
26 /// Successful data payload
27 Data,
28 /// Error payload
29 Error,
30}
31
32use crate::error::FlagdError;
33
34/// Trait for flag configuration connectors (gRPC, file, etc.)
35///
36/// Connectors are responsible for fetching flag configurations from external sources
37/// and providing them as a stream of payloads. Implementations must be thread-safe
38/// (Send + Sync) as they may be used in async contexts.
39#[async_trait::async_trait]
40pub trait Connector: Send + Sync {
41 /// Initialize the connector and start fetching data
42 async fn init(&self) -> Result<(), FlagdError>;
43
44 /// Gracefully shutdown the connector and release resources
45 async fn shutdown(&self) -> Result<(), FlagdError>;
46
47 /// Get the stream of payloads from this connector
48 fn get_stream(&self) -> Arc<Mutex<Option<Receiver<QueuePayload>>>>;
49}