Jinesh Parekh
Jinesh Parekh

Reputation: 2141

Is Spring Batch an overkill

I need to load a CSV into a database once a week. There is some data massaging required as the CSV file has data for 2 tables. So I will have to process the CSV file a bit, probably convert it into 2 different CSV files and load it into a database.

I already have quartz configured in place. Do you think it would be an overkill to use spring batch to do the job? I am wondering when should I use it and when should I just do away with quartz bean do the processing itself.

Upvotes: 6

Views: 5599

Answers (2)

gavenkoa
gavenkoa

Reputation: 48753

Spring Batch adds extra requirements and maintenance pain:

  • You need to structure your code in String Batch idiomatic way (implement thier interfaces).
  • You need to write some XML or Java configs - one extra DSL to learn.
  • You need admin tool to start / stop / monitor execution. Spring Batch Admin is officially deprecated and unmaintained.
  • You need to maintain BATCH_ tables, define index strategy (missing by default), define periodic tables cleanups.
  • I've learnt Spring Batch via debug sessions and source code as documentation touches only simple cases (like CSV -> DB).

Upvotes: 3

Josh Long
Josh Long

Reputation: 2040

Spring Batch is perfect for these kinds of jobs because it reduces the parts that you have to care about. In this case, all you care about is massaging the data and then inserting into two different tables. You could read the data using the FileItemReader. Then use an ItemProcessor to change any incoming data and output the correct data, properly massaged. You supply the itemProcessor since it's your custom Java logic. Then you can use the JdbcItemWriter or simply plug in your own.

The nicest part about this is that it's [a] super commonplace so there's lots and lots and lots of examples (see: Spring Batch 2.0 – Part II – Flat File To Database or joshlong/joshlong-examples/spring-batch-starter or the samples in Spring batch itself for inspiration) and [b] it's mostly declarative. You don't have to worry about the things you don't care about - you're not in the business of figuring out how to correctly parse CSV files, or even how to read files in in a scalable way. You just want to make sure the data is valid and make sure it ends up where it's supposed to end up.

Upvotes: 7

Related Questions