Getting Started
Add drasi-lib to your Rust project and run your first continuous query
The quickest way to get started using drasi-lib is to create a simple example. This minimal example monitors a mock sensor source and reacts when temperature exceeds 75°C:
Add drasi-lib dependencies
Add drasi-lib to your Cargo.toml, along with tokio and the source and reaction crates you need:
[dependencies]
drasi-lib = "0.3"
drasi-source-mock = "0.1"
drasi-reaction-log = "0.1"
tokio = { version = "1", features = ["full"] }
Write your first drasi-lib application
use drasi_lib::{DrasiLib, Query};
use drasi_source_mock::{MockSource, MockSourceConfig};
use drasi_reaction_log::{LogReaction, LogReactionConfig};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a mock sensor source
let source = MockSource::new("sensors", MockSourceConfig {
data_type: "sensor".to_string(),
interval_ms: 1000,
})?;
// Create a log reaction for alerts
let reaction = LogReaction::new(
"alerts",
vec!["high-temp".to_string()],
LogReactionConfig::default(),
)?;
// Build and run
let core = DrasiLib::builder()
.with_source(source)
.with_reaction(reaction)
.with_query(
Query::gql("high-temp")
.query("MATCH (s:Sensor) WHERE s.temperature > 75 RETURN s")
.from_source("sensors")
.build()
)
.build()
.await?;
core.start().await?;
tokio::signal::ctrl_c().await?;
core.stop().await
}
When a sensor’s temperature crosses 75°C, you’ll receive a change event with the sensor data. When it drops back below, you’ll receive a deletion event—enabling precise “enter/exit” logic without manual state tracking.
Documentation Resources
For complete documentation, builder API reference, and advanced configuration:
GitHub README
Complete builder API, configuration options, and plugin development guides
crates.io
Package info, version history, and dependencies
docs.rs
API documentation with type definitions and usage examples
Feedback
Was this page helpful?
Glad to hear it! Please tell us what you found helpful.
Sorry to hear that. Please tell us how we can improve.