Skip to main content

Crate drasi_source_application

Crate drasi_source_application 

Source
Expand description

Application Source Plugin for Drasi

This plugin enables programmatic event injection into Drasi’s continuous query processing pipeline. Unlike other sources that connect to external data systems, the application source allows your Rust code to directly send graph data changes.

§Architecture

The application source uses a handle-based pattern:

  • ApplicationSource: The source component that processes events
  • ApplicationSourceHandle: A clonable handle for sending events from anywhere in your code

§API Overview

The ApplicationSourceHandle provides high-level methods for common operations:

§Building Properties

Use the PropertyMapBuilder to construct property maps fluently:

use drasi_source_application::PropertyMapBuilder;

let props = PropertyMapBuilder::new()
    .string("name", "Alice")
    .integer("age", 30)
    .float("score", 95.5)
    .bool("active", true)
    .build();

§Configuration

The application source has minimal configuration since it receives events programmatically rather than connecting to an external system.

FieldTypeDefaultDescription
propertiesobject{}Custom properties (passed through to properties())

§Bootstrap Support

The application source supports pluggable bootstrap providers via the BootstrapProvider trait. Configure a bootstrap provider using set_bootstrap_provider() or through the builder pattern. Common options include ApplicationBootstrapProvider for replaying stored events, or any other BootstrapProvider implementation.

§Example Configuration (YAML)

source_type: application
properties: {}

§Usage Example

use drasi_source_application::{
    ApplicationSource, ApplicationSourceConfig, ApplicationSourceHandle,
    PropertyMapBuilder
};
use std::sync::Arc;

// Create the source and handle
let config = ApplicationSourceConfig::default();
let (source, handle) = ApplicationSource::new("my-app-source", config)?;

// Add source to Drasi
let source = Arc::new(source);
drasi.add_source(source).await?;

// Clone handle for use in different parts of your application
let handle_clone = handle.clone();

// Insert a node
let props = PropertyMapBuilder::new()
    .string("name", "Alice")
    .integer("age", 30)
    .build();

handle.send_node_insert("user-1", vec!["User"], props).await?;

// Insert a relationship
let rel_props = PropertyMapBuilder::new()
    .string("since", "2024-01-01")
    .build();

handle.send_relation_insert(
    "follows-1",
    vec!["FOLLOWS"],
    rel_props,
    "user-1",  // start node
    "user-2",  // end node
).await?;

// Update a node
let updated_props = PropertyMapBuilder::new()
    .integer("age", 31)
    .build();

handle.send_node_update("user-1", vec!["User"], updated_props).await?;

// Delete a node
handle.send_delete("user-1", vec!["User"]).await?;

§Use Cases

  • Testing: Inject test data directly without setting up external sources
  • Integration: Bridge between your application logic and Drasi queries
  • Simulation: Generate synthetic events for development and demos
  • Hybrid Sources: Combine with other sources for complex data pipelines

Re-exports§

pub use config::ApplicationSourceConfig;

Modules§

config
Configuration types for application source.

Structs§

ApplicationSource
A source that allows applications to programmatically inject events.
ApplicationSourceHandle
Handle for programmatic event injection into an Application Source
PropertyMapBuilder
Builder for creating graph element property maps