This is an introduction to Spring Batch Framework. After reading this presentation, you will be able to know how Spring Batch works, and you will be able to download a maven project as an example.
2. Agenda
• What is Spring Batch?
• What is Batch Processing?
• Spring Batch Concepts
• Jobs, steps.
• Readers, processors, writers.
• Chunk oriented processing (COP).
• Job and step listeners.
• Understanding code
• Summary
• Spring Batch Features in Upcoming Talks
• Q & A
www.senzil.com– By GuillermoSalazar
2
3. What is Spring Batch?
• Spring Batch is part of Spring Framework.
• Java based framework for batch processing.
– A lightweight, comprehensive batch framework.
– POJO-based development approach, known from the Spring
Framework.
– See more about POJO in https://spring.io/understanding/POJO.
• Based on principles and advantages of Spring Framework.
• It supports:
– Concurrent batch processing.
– Massively parallel batch processing.
– Manual or scheduled restart after failure.
– Commit batch periodically.
– Other features.
www.senzil.com– By GuillermoSalazar
3
4. What is Batch Processing?
• The batch processing is used for batch applications to process
high volume of data.
• Usually a batch application:
– Reads a high amount of data from several sources (DB, CSV/XML files,
queues, web services, others).
– Process or transforms the data read following certain business rules.
– Writes the transformed data in one or more destinations.
• Usually batch applications are crucial for businesses because
of:
– The amount of data they handle.
– The processing times of the data.
• They follow the ETL principle in datawarehousing / datamining.
www.senzil.com– By GuillermoSalazar
4
5. Spring Batch Concepts – 1/4
Import users
depending on
their economic
situation.
Step
#1
Read and
validate the
user
information
imported.
Step
#2
Read and
analyze users
information to
send them
special offers
about our
products.
Step
#3
Job
• It is the most important concept in Spring Batch.
• It needs a JobLauncher instance to be executed.
• It can contain one or more steps, which can be executed in
sequence or parallel.
Step
• It encapsulates an independent and sequential phase of a job.
• It contains exactly a Reader, a Writer and optionally a Processor.
www.senzil.com– By GuillermoSalazar
5
6. Spring Batch Concepts – 2/4
• Reader
• It represents an abstraction which is responsible for recovering
data from a source.
• When it can not retrieve more data, it returns null.
• Writer
• It represents the output for a step in chunk oriented processing.
• There are various implementations out-of-the-box.
• It has not any knowledge about the reader implementation.
• Processor
• It is optional in the chunk oriented processing.
• It represents the business process for each item, and it can
return a null, when that item doesn’t need to be written.
www.senzil.com– By GuillermoSalazar
6
7. Spring Batch Concepts – 3/4
When a Step is executed, it:
• Reads an item at a time until the
value of the property “chunkSize or
commitInterval” in the current step
is reached.
• After that, it process all the items
read, an item at a time.
• Finally, it writes all the items read
and processed in the last iteration.
• The process is executed again until
all the items are written.
www.senzil.com– By GuillermoSalazar
7
8. Spring Batch Concepts – 4/4
Listeners
– Bring us the possibility to perform some actions during
the execution of a Job and/or Step.
– There are some types of listeners:
• StepExecutionListener
• ChunkListener
• ItemReadListener
• ItemProcessListener
• ItemWriteListener
• SkipListener
www.senzil.com– By GuillermoSalazar
8
9. Understanding Java Code
The dependency versions used in the samples are:
• Spring Framework - 4.2.0.RELEASE
• Spring Batch - 3.0.5.RELEASE
Show Java code in Eclipse
www.senzil.com– By GuillermoSalazar
9
10. Summary
• Spring Batch provides a highly
scalable framework.
• It is really easy-to-use, and
customizable batch framework.
• Spring patterns and practices have
been leveraged allowing
developers to focus on business
logic.
www.senzil.com– By GuillermoSalazar
10
11. Spring Batch Features in
Upcoming Talks
• Late binding parameters.
• Tasklet oriented processing.
• Unit test cases for jobs and steps.
• Step configuration for restart strategies.
• Flow strategies:
– Conditional flow.
– Split flow.
– Sequential flow.
• Spring Batch Admin
www.senzil.com– By GuillermoSalazar
11
13. Thanks for your attention
guillermo@senzil.com
If you have questions, you can contact me:
bitbucket.org/salazarguille/spring_batch_introduction
You can get the source code in the below URL:
www.senzil.com– By GuillermoSalazar