Expand description
Microsoft SQL Server CDC Source for Drasi
This source plugin captures data changes from MS SQL Server databases using Change Data Capture (CDC). It monitors CDC change tables and converts changes to Drasi source events.
§Features
- Real-time change capture via CDC polling
- LSN-based progress tracking with StateStore persistence
- Automatic LSN validation and recovery
- Support for INSERT, UPDATE, DELETE operations
- Transaction grouping
- Primary key discovery and custom key configuration
§Prerequisites
Before using this source, you must:
-
Enable CDC on the database:
EXEC sys.sp_cdc_enable_db; -
Enable CDC on tables you want to monitor:
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'YourTable', @role_name = NULL; -
Ensure SQL Server Agent is running (required for CDC)
§Example
use drasi_source_mssql::{MsSqlSource, StartPosition};
use drasi_lib::Source;
let source = MsSqlSource::builder("mssql-source")
.with_host("localhost")
.with_database("production")
.with_user("drasi_user")
.with_password("secure_password")
.with_tables(vec!["orders".to_string(), "customers".to_string()])
.with_start_position(StartPosition::Beginning) // Capture all retained changes
.build()?;
source.start().await?;Re-exports§
pub use decoder::CdcOperation;pub use lsn::Lsn;
Modules§
- config
- Configuration for MS SQL CDC source
- connection
- MS SQL connection management using Tiberius
- decoder
- CDC operation decoder
- descriptor
- MS SQL source plugin descriptor and configuration DTOs.
- error
- Error types for MS SQL CDC source
- keys
- Primary key discovery and element ID generation
- lsn
- LSN (Log Sequence Number) handling for MS SQL CDC
- stream
- CDC polling stream implementation
- types
- Type conversion from MS SQL to Drasi ElementValue
Structs§
- MsSql
Connection - MS SQL connection wrapper
- MsSql
Source - MS SQL CDC Source
- MsSql
Source Builder - Builder for MS SQL source
- MsSql
Source Config - MS SQL CDC source configuration
- Primary
KeyCache - Cache of primary keys for tables
- Table
KeyConfig - Table key configuration for custom primary keys
Enums§
- Auth
Mode - Authentication mode for MS SQL Server
- Connection
Error - Connection-related error types
- Encryption
Mode - TLS/SSL encryption mode
- LsnError
- LSN-related error types
- MsSql
Error - Errors specific to MS SQL CDC operations
- MsSql
Error Kind - Simplified error classification for control flow decisions
- Primary
KeyError - Primary key related error types
- Start
Position - Starting position when no LSN is found in the state store
Functions§
- validate_
sql_ identifier - Validate a SQL identifier to prevent SQL injection