The Drasi Reactions SDK is a cross-language development toolkit for implementing and processing the Reactions (reactor) capabilities of the Drasi platform. The SDK currently supports three mainstream programming languages: JavaScript/TypeScript, Python, and .NET.
Main functions and features:
-
Core functions:
- Handle change events from Continuous Query (ChangeEvent)
- Handle control events (ControlEvent)
- Supports parsing and management of query configurations
- Provide event subscription and processing mechanisms
-
Main Event Types:
- ChangeEvent: Contains the addition, deletion and update information of query results
- ControlEvent: Process control signals such as start and stop
Supported language implementations:
JavaScript/TypeScript version:
import { DrasiReaction, ChangeEvent } from '@drasi/reaction-sdk';
let myReaction = new DrasiReaction(async (event: ChangeEvent) => {
(`Received change sequence: ${} for query ${}`);
// Process the added results
for (let added of ) {
(`Added result: ${(added)}`);
}
// Process the results of deletion
for (let deleted of ) {
(`Removed result: ${(deleted)}`);
}
// Process update results
for (let updated of ) {
(`Updated result - before: ${()}, after: ${()}`);
}
});
();
Python version:
from import ChangeEvent
from import DrasiReaction
async def change_event(event: ChangeEvent, query_configs: dict[str, Any] | None = None):
print(f"Received change sequence {} for query {}")
if :
print(f"Added result: {}")
if :
print(f"Removed result: {}")
if :
print(f"Updated result - before: {[0].before}, after {[0].after}")
reaction = DrasiReaction(on_change_event=change_event)
()
.NET version:
var reaction = new ReactionBuilder()
.UseChangeEventHandler(async (evt, queryConfig) => {
($"Received change event from query {} sequence {}");
foreach (var item in )
($"Added result: {item}");
foreach (var item in )
($"Updated result, before {}, after {}");
foreach (var item in )
($"Deleted result: {item}");
})
.Build();
await ();
-
Advanced Features:
- Supports custom query configuration (Query Configuration)
- Support YAML configuration file parsing
- Provide configuration value acquisition tool
- Supports dependency injection (especially in .NET versions)
- Provides complete event processing lifecycle management
-
Architecture features:
- Implementing the publish and subscription model based on Dapr
- Support asynchronous event processing
- Provides elegant error handling and logging
- Support hot loading of configuration files
The SDK is designed to provide a simple but powerful interface that allows developers to easily implement and manage reactor functions of the Drasi platform. No matter which programming language is used, events can be handled and configuration managed through similar API design patterns.