Skip to main content

Module data_sources

Module data_sources 

Source
Expand description

Types for implementing custom FDv2 data sources.

This module is experimental and not subject to semantic versioning. Its API may change in any release.

§Examples

Implement a custom synchronizer and add it to a data system.

use launchdarkly_server_sdk::data_sources::{
    DataSourceBuildContext, FDv2SourceEvent, FDv2SourceEventFuture, FDv2SourceResult,
    FDv2SynchronizerConfig, Selector, Synchronizer, SynchronizerFactory,
};
use launchdarkly_server_sdk::{ConfigBuilder, DataSystemBuildError, DataSystemBuilder};

struct MySynchronizer;

impl Synchronizer for MySynchronizer {
    fn next(&mut self, _selector: Selector) -> FDv2SourceEventFuture<'_> {
        Box::pin(async {
            FDv2SourceEvent {
                result: FDv2SourceResult::Goodbye,
                fdv1_fallback: None,
            }
        })
    }

    fn name(&self) -> &str {
        "my-synchronizer"
    }
}

struct MyFactory;

impl SynchronizerFactory for MyFactory {
    fn create(&self) -> Box<dyn Synchronizer> {
        Box::new(MySynchronizer)
    }
}

#[derive(Clone)]
struct MyConfig;

impl FDv2SynchronizerConfig for MyConfig {
    fn build_synchronizer(
        &self,
        _context: &DataSourceBuildContext,
    ) -> Result<Box<dyn SynchronizerFactory>, DataSystemBuildError> {
        Ok(Box::new(MyFactory))
    }

    fn to_owned(&self) -> Box<dyn FDv2SynchronizerConfig> {
        Box::new(self.clone())
    }
}

let mut data_system = DataSystemBuilder::custom();
data_system.synchronizer(MyConfig);
ConfigBuilder::new("sdk-key").data_system(&data_system);

Structs§

ChangeSet
A batch of flag and segment changes delivered by a data source.
DataSourceBuildContext
The inputs a data source needs to build itself.
ErrorInfo
Describes an error surfaced by a data source.
FDv1FallbackDirective
An instruction from LaunchDarkly to fall back to the FDv1 protocol.
FDv2SourceEvent
A source result paired with any FDv1 fallback directive seen on the same response.
RequestHeaders
The HTTP headers attached to every FDv2 request.

Enums§

ChangeSetKind
Whether a change set is a full payload, an incremental update, or carries no changes.
ErrorKind
Classifies why a data source is interrupted or has failed.
FDv2SourceResult
The outcome of a single data source poll or stream read.
ItemChange
A single flag or segment change within a change set.

Traits§

FDv2InitializerConfig
A configured FDv2 source usable as an initializer.
FDv2SynchronizerConfig
A configured FDv2 source usable as a synchronizer.
Initializer
A data source that can obtain an initial payload.
InitializerFactory
Produces a fresh initializer each time the orchestrator starts a run.
Synchronizer
A data source that keeps flag data up to date.
SynchronizerFactory
Produces a fresh synchronizer each time the orchestrator starts a run.

Type Aliases§

FDv2SourceEventFuture
The future returned by an initializer or synchronizer as it produces an event.
Selector
Identifies a point in the flag-data stream, echoed back to request the next changes.