首页 文章

Spring集成配置等待异步批处理作业的结果

提问于
浏览
2

我使用Spring Batch管理项目,我有一个工作,异步处理特定文件夹中的文件 . 目前我通过传递相关的作业参数通过批量管理ui运行它 .

现在,我正在尝试使用文件入站通道适配器自动执行此过程 . 我已经配置了服务激活器,它会在收到文件时调用批处理作业 . 第一个文件上载作业完成后,我现在有了一个新要求来调用另一个批处理作业 . 为此,我创建了另一个使用第一个服务激活器的输出通道的服务激活器 . 但由于批处理作业异步运行,因此下一批处理作业将立即执行 . 有没有办法让第二个批处理作业等到第一个批处理作业完成 .

我目前的配置是

<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-->

任何帮助将非常感谢 .

1 回答

相关问题