Crate spring_batch_rs

source ·
Expand description

Spring-Batch for Rust

🐞 A toolkit for building enterprise-grade batch applications

crate docs build status Discord chat CodeCov license

Spring-Batch for Rust

Spring Batch for Rust, offers a robust and flexible framework for the development of batch processing applications, addressing the challenges of handling large-scale data processing tasks efficiently and reliably. It provides developers a comprehensive toolkit for building enterprise-grade batch applications.

Features

  • CSV reader and writer
  • JSON reader and writer

Roadmap

  • XML reader and writer
  • SQL reader and writer
  • MongoDB reader and writer
  • Kafka reader and writer
  • Pulsar reader and writer
  • Retry/Skip policies
  • Save execution data in database

Example

[dependencies]
spring-batch-rs = { version = "0.1.1", features = ["full"] }

Then, on your main.rs:

 #[derive(Deserialize, Serialize, Debug, Clone)]
 struct Record {
     year: u16,
     make: String,
     model: String,
     description: String,
 }

 impl fmt::Display for Record {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(
             f,
             "(year={}, make={}, model={}, description={})",
             self.year, self.make, self.model, self.description
         )
     }
 }

 fn main() -> Result<(), BatchError> {
    let csv = "year,make,model,description
    1948,Porsche,356,Luxury sports car
    1967,Ford,Mustang fastback 1967,American car";

    let mut reader = CsvItemReaderBuilder::new().delimiter(b',').from_reader(csv.as_bytes());

    let mut writer = LoggerWriter::new();

    let mut step: Step<Record, Record> = StepBuilder::new()
        .reader(&mut reader)
        .writer(&mut writer)
        .chunk(4)
        .build();

    step.execute();
    Ok(())
 }

Read CSV file with headers

$ git clone git://github.com/sboussekeyt/spring-batch-rs
$ cd spring-batch-rs
$ cargo run --example csv_reader_with_headers --all-features < examples/data/cars_with_headers.csv

Read Json file

$ git clone git://github.com/sboussekeyt/spring-batch-rs
$ cd spring-batch-rs
$ cargo run --example json_reader --all-features < examples/data/persons.json

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions

Modules

  • Error types for batch operations
  • Set of items readers / writers (for exemple: csv reader and writer)

Structs

Enums