spring-batch

Calling another job from a processor in spring batch

笑着哭i 提交于 2019-12-06 10:42:30
问题 I have a job(= JobA ) that reads and processes an input file - this Job is defined using a reader, writer, several processors, listeners and exception handlers and i don't want to change this job definition mainly for backwards compatibility reasons I want to implement another job(= JobB ) that reads files from a directory with a certain criteria and in a certain order and then sends the files to be processed by JobA I was looking into [MultiResourceItemReader][1] [1]: http://docs.spring.io

spring batch read write execution time

大兔子大兔子 提交于 2019-12-06 10:41:13
I'm looking best way to measure execution time of Spring Batch read, procced and write action. In Meta-data there are information about whole step but not about each action. I'm thinking about listeners but is it proper solution ? Thank you for all of Yours answers! The beforeXXX and afterXXX methods of ItemReadListener , ItemProcessListener and ItemWriteListener interfaces are the correct way to measure in-step performance. Just initialize your timer at beforeXXX() and output the result at afterXXX() method. 来源: https://stackoverflow.com/questions/11446366/spring-batch-read-write-execution

Create new output file using FlatFileItemWriter in spring-batch

眉间皱痕 提交于 2019-12-06 08:08:19
问题 I have a simple spring batch job - read a file line by line, do something with the input string, and write some output. Output file contains every line of input plus some processing status for that line (success/failure.) The reads a file from: <dir>/<inputFolder>/<inputFileName> and writes processed output to <dir>/<outputFolder>/<inputFileName> All these values are passed as jobParameters File Reader is like so: <bean id="itemReader" class="org.springframework.batch.item.file

Spring Batch - where does the process run

冷暖自知 提交于 2019-12-06 08:01:22
I'm trying to wrap my head around Spring Batch, and while many tutorials show great examples of code, i feel like i'm missing how the "spring batch engine" works. Scenario 1 - On user creation, create user at external service. Web request CreateLocalUser() launch job CreateExternalUser() CreateExternalUser() can fail because of many reasons, so we want to be able to retry and log errors, which Spring Batch can do for us. Also it's a decoupled process that has nothing to do with the creation of our local user. Where does the job run? Will it run in the same thread as the web request, which

How to skip batch step when condition is false

不羁的心 提交于 2019-12-06 08:01:07
问题 I have one basis job with one basic step. This jobs is executing every x second (I am using quartz for this). Then in my config class I also have variable "runStep". Where should I add this attribute and run my step only if runStep is true ? <batch:job id="export1" parent="baseJob"> <batch:step id="registruj" parent="baseStep"> <tasklet> <chunk reader="registrujReader" processor="registrujProcessor" writer="registrujWriter" commit-interval="1" /> </tasklet> </batch:step> </batch:job> <bean id

Can Spring Batch jobs be configured at run time with dynamic steps?

一世执手 提交于 2019-12-06 08:00:34
I am looking at Spring Batch 2.0 to implement a pipeline process. The process is listening to some event, and needs to perform a set of transformation steps base on the event type and its content. Spring batch seem to be a great fit. However, going through the documentation, every example have them job and its steps configured in xml. Does the framework support creating jobs during run-time and configuring the steps dynamically? the job configuration itself is set before the job runs, but it is possible to create a flexible job configuration with conditional flows you can't just change the job

How to implement reader for multiple queries but same output item?

自闭症网瘾萝莉.ら 提交于 2019-12-06 07:35:38
For a Spring batch job, we have 2 different queries on the same table. The requirement is to have a reader that execute two queries to read data from the same table. One way could be : <batch:step id="firstStep" next="secondStep"> <batch:tasklet> <batch:chunk reader="firstReader" writer="firstWriter" commit- interval="2"> </batch:chunk> </batch:tasklet> </batch:step> <batch:step id="secondStep" next="thirdStep"> <batch:tasklet> <batch:chunk reader="secondReader" writer="secondWriter" commit-interval="2"> </batch:chunk> </batch:tasklet> </batch:step> But this demands totally another step to be

Configuring Spring Batch Steps in Parallel (Split) using Annotations

给你一囗甜甜゛ 提交于 2019-12-06 07:35:31
Where ever I look into Spring Batch documentation for executing steps in parallel, I only see the configuration of it via XML like given below. <split id="split1" next="step4"> <flow> <step id="step1" parent="s1" next="step2"/> <step id="step2" parent="s2"/> </flow> <flow> <step id="step3" parent="s3"/> </flow> I am writing an application using Spring Batch where I have used Spring Boot as well, and all of my configurations are done using Annotations. Is there a I can configure a Split Step using Java configuration? I checked the API documentation of Step interface in Spring Batch, but it

How to access jobParameters in SpringBatch as a bean?

大城市里の小女人 提交于 2019-12-06 07:12:36
I have created jobParameter bean definition like below : <bean id="executionContext" class="com.test.ExecutionContextImpl" scope="step" > <property name="toDate" value="#{jobParameters['toDate']}" /> <property name="fromDate" value="#{jobParameters['fromDate']}" /> </bean> and I am using the bean while defining reader like: <bean id="fileDownloadReader" class="com.test.FileDownloadReader" scope="step" > <property name="execCtx" ref="executionContext" /> </bean> While invoking the job from command line am getting below exception. with scope=step (in bean definition): 2013/07/01 08-52-19,057:OUT

Spring batch to aggregate values and write single value

江枫思渺然 提交于 2019-12-06 07:09:12
I am using spring batch and I need to achieve the following Read a csv file which has details like date and amount Aggregate the sum of all amounts for a same date Persist one entry with date and the sum I have used batch in the past and I thought of the following approach. Create a batch with 2 steps. Step 1: Reader: Loop through the entire file using FlatFileItemReader Processor: Populate a map with Key as date and value as amount. If entry is present then get the value and add it to the new value Writer: No operation writer as I do not wish to write Step 2: Reader: Loop through the values