Aller au contenu

Feature Flags Reference

Ce contenu n’est pas encore disponible dans votre langue.

Spring Batch RS uses feature flags to enable optional functionality. This keeps the core library lean while allowing you to opt into specific capabilities.

These features are always included and require no feature flags:

Core Traits

ItemReader, ItemWriter, ItemProcessor, Tasklet

Job & Step

JobBuilder, StepBuilder, execution management

Error Handling

BatchError, fault tolerance, skip/retry logic

Logger Writer

LoggerWriter for debugging output


[dependencies]
spring-batch-rs = { version = "0.1", features = ["csv"] }

Provides:

  • CsvItemReader<R> - Read CSV files and strings
  • CsvItemWriter<O, W> - Write CSV files

Use for:

  • Comma/tab/custom-delimited files
  • Headers or headerless CSV
  • Data import/export pipelines

Dependencies:

  • csv crate

[dependencies]
spring-batch-rs = { version = "0.1", features = ["json"] }

Provides:

  • JsonItemReader<I, R> - Streaming JSON array reader
  • JsonItemWriter<O, W> - JSON array writer with pretty-printing

Use for:

  • REST API data processing
  • Configuration file manipulation
  • JSON data transformation

Dependencies:

  • serde_json crate

[dependencies]
spring-batch-rs = { version = "0.1", features = ["xml"] }

Provides:

  • XmlItemReader<R, I> - Extract elements by tag name
  • XmlItemWriter<O, W> - Generate XML documents

Use for:

  • SOAP/XML API integration
  • RSS/Atom feed processing
  • Legacy XML data migration

Dependencies:

  • quick-xml crate
  • serde-xml-rs crate

[dependencies]
spring-batch-rs = { version = "0.1", features = ["rdbc-postgres"] }
sqlx = { version = "0.7", features = ["runtime-tokio-native-tls", "postgres"] }

Provides:

  • PostgresRdbcItemReader<I> - Paginated PostgreSQL queries
  • PostgresItemWriter<O> - Bulk PostgreSQL inserts

Use for:

  • Reading from PostgreSQL tables
  • ETL from PostgreSQL to other systems
  • Bulk data loading

Dependencies:

  • sqlx with PostgreSQL support
  • tokio async runtime

[dependencies]
spring-batch-rs = { version = "0.1", features = ["rdbc-mysql"] }
sqlx = { version = "0.7", features = ["runtime-tokio-native-tls", "mysql"] }

Provides:

  • MysqlRdbcItemReader<I> - Paginated MySQL queries
  • MysqlItemWriter<O> - Bulk MySQL inserts

Use for:

  • MySQL/MariaDB data extraction
  • Database migrations
  • Reporting queries

Dependencies:

  • sqlx with MySQL support
  • tokio async runtime

[dependencies]
spring-batch-rs = { version = "0.1", features = ["rdbc-sqlite"] }
sqlx = { version = "0.7", features = ["runtime-tokio-native-tls", "sqlite"] }

Provides:

  • SqliteRdbcItemReader<I> - Paginated SQLite queries
  • SqliteItemWriter<O> - Bulk SQLite inserts

Use for:

  • Embedded database processing
  • Local data stores
  • Testing and development

Dependencies:

  • sqlx with SQLite support
  • tokio async runtime

[dependencies]
spring-batch-rs = { version = "0.1", features = ["mongodb"] }
mongodb = "2.8"

Provides:

  • MongodbItemReader<I> - Cursor-based MongoDB queries
  • MongodbItemWriter<O> - Bulk MongoDB inserts

Use for:

  • Document database processing
  • MongoDB data migration
  • Collection transformations

Dependencies:

  • mongodb official driver
  • Requires WithObjectId trait implementation

[dependencies]
spring-batch-rs = { version = "0.1", features = ["orm"] }
sea-orm = { version = "0.12", features = ["sqlx-postgres", "runtime-tokio-native-tls"] }

Provides:

  • OrmItemReader<I> - Read using SeaORM entities
  • OrmItemWriter<O> - Write using SeaORM entities

Use for:

  • Type-safe database access
  • Working with existing SeaORM models
  • Complex query building

Dependencies:

  • sea-orm with appropriate database backend

[dependencies]
spring-batch-rs = { version = "0.1", features = ["zip"] }

Provides:

  • ZipTasklet - Compress files and directories

Capabilities:

  • Configurable compression levels (0-9)
  • File filtering with glob patterns
  • Directory structure preservation
  • Single file or directory compression

Use for:

  • Backup operations
  • Log file archival
  • Report packaging

Dependencies:

  • zip crate

[dependencies]
spring-batch-rs = { version = "0.1", features = ["ftp"] }

Provides:

  • FtpTasklet - Upload/download via FTP/FTPS

Capabilities:

  • FTP and FTPS (TLS) support
  • Upload and download operations
  • Authentication support
  • Connection management

Use for:

  • File distribution
  • Remote backup
  • Legacy system integration

Dependencies:

  • ftp crate

[dependencies]
spring-batch-rs = { version = "0.1", features = ["fake"] }

Provides:

  • PersonReader - Generate fake person data
  • Person struct with realistic test data

Use for:

  • Testing batch jobs
  • Development without real data
  • Performance testing

Dependencies:

  • fake crate

File Processing

features = ["csv", "json", "xml"]

Process all common file formats

Database ETL

features = ["rdbc-postgres", "rdbc-mysql", "csv", "json"]

Database to file exports and imports

Complete Pipeline

features = ["csv", "json", "rdbc-postgres", "zip", "ftp"]

End-to-end data pipeline with delivery

NoSQL Processing

features = ["mongodb", "json", "csv"]

MongoDB data transformation


Feature CombinationAdditional Compile Time
Core onlyBaseline
+ csv, json, xml+10-15 seconds
+ Single database+30-45 seconds (sqlx)
+ All databases+45-60 seconds
+ mongodb+20-30 seconds
+ All features+60-90 seconds
Feature CombinationApproximate Size (Release)
Core only~1 MB
+ File formats~2 MB
+ Single database~4-5 MB
+ All databases~7-9 MB
+ All features~10-12 MB

Use conditional compilation for feature-specific code:

#[cfg(feature = "csv")]
use spring_batch_rs::item::csv::CsvItemReaderBuilder;
#[cfg(feature = "rdbc-postgres")]
use spring_batch_rs::item::rdbc::postgres::PostgresItemWriterBuilder;
fn create_reader() -> Box<dyn ItemReader<MyType>> {
#[cfg(feature = "csv")]
{
Box::new(CsvItemReaderBuilder::new().from_path("data.csv").unwrap())
}
#[cfg(not(feature = "csv"))]
{
panic!("CSV feature not enabled")
}
}

Check available features at runtime:

fn check_features() {
println!("CSV support: {}", cfg!(feature = "csv"));
println!("JSON support: {}", cfg!(feature = "json"));
println!("PostgreSQL support: {}", cfg!(feature = "rdbc-postgres"));
}

Before:

[dependencies]
spring-batch-rs = "0.1"

After:

[dependencies]
spring-batch-rs = { version = "0.1", features = ["csv", "json", "rdbc-postgres"] }
sqlx = { version = "0.7", features = ["runtime-tokio-native-tls", "postgres"] }

If your project grows and you want to optimize:

  1. Audit your imports and identify which readers/writers you use
  2. Map them to feature flags using the tables above
  3. Remove unused features from Cargo.toml
  4. Run cargo clean and rebuild

Can’t find a feature you need? We welcome contributions!