質問

I use Spring Batch admin project in which I have got a job which processes files from a particular folder asynchronously. Currently I run it via batch admin ui by passing the relevant job parameters.

Now, I am trying to automate this process by using file inbound channel adapter. I have configured the service activator which would invoke the batch job whenever it receives a file. I have a new requirement now to invoke another batch job once the the first file upload job is complete . To do this, I have created another service activator that uses the output channel of the first service activator. But since the batch job runs asynchronously, then next batch job is getting executed immediately. Is there a way for the second batch job to wait till the first batch job completes.

My current configuation is

 <file:inbound-channel-adapter id="filesIn" directory="file:${input.directory}" filename-pattern="*.csv" prevent-duplicates="true">
    <integration:poller id="poller" fixed-delay="10000"/>
</file:inbound-channel-adapter>
<integration:channel id="statusChannel"/>

<integration:service-activator input-channel="filesIn" output-channel="statusChannel"
                               ref="handler" method="process"/>

<bean id="handler" class="AnalysisMessageProcessor"> 
    <property name="job" ref="A-importGlobalSettingsDataJob"/> <!--1st job -->
    <property name="requestHandler" ref="jobMessageHandler"/>
</bean>       

<bean id="jobMessageHandler" class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler">
    <constructor-arg ref="jobLauncher" /> <!--spring batch admins async job launcher -->
</bean>                         

<integration:service-activator input-channel="statusChannel" ref="jobHandler" method="process"/>   
<bean id="jobHandler" class="JobHandler"> <!--This Job handler should get invoked only after the 1st batch job is completed. Currently I am just printing the exit status code of 1st job-->

Any help would be very much appreciated.

役に立ちましたか?

解決

You basically have 2 options:

  • Actively Poll for the Job Execution Status
  • Trigger the next Batch Job (Part of a second Spring Integration flow?) in an event-driven approach using listeners

For the first approach checkout "Querying the Repository" (Part of the Spring Batch reference documentation):

The second option would generally be best. Thus, I believe you may want to look into using a Spring Batch JobExecutionListener

Please checkout the section "Providing Feedback with Informational Messages" in the following document:

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top