簡單的step無法滿足我們的要求,比如優惠券到賬業務。根據需求拆分爲2部分,即到賬業務與到賬通知業務。那麼我們需要先執行到賬再執行通知,這裏就需要用到Flow Step。
Flow Step的使用配置與一般的沒什麼不同唯一需要注意的是作爲入口的job的地方。
<!--允許任務重啓:restartable="true" -->
<batch:job id="tranIntoAccountJob" restartable="true">
<!--定義Flow Step -->
<batch:flow id="doTranIntoFlow" parent="tranIntoFlow" />
</batch:job>
<batch:flow id="tranIntoFlow" >
<!--<batch:step id="doMaster" parent="tranIntoMaster"/>-->
<batch:step id="tranIntoMaster" next="tranInfoDB" >
<batch:partition step="tranInfoDB" partitioner="tranIntoAccountPartitioner" >
<batch:handler grid-size="10" task-executor="taskExecutor" />
</batch:partition>
<batch:listeners >
<batch:listener ref="pickUpListener" before-step-method="beforeStep" />
</batch:listeners>
</batch:step>
<!-- 紅包到賬 -->
<batch:step id="tranInfoDB" next="tranInfoStep" >
<batch:tasklet transaction-manager="main_txManager">
<batch:chunk reader="tranIntoAccountReader" writer="tranIntoAccountWriter" processor="tranIntoAccountProcessor"
commit-interval="100">
</batch:chunk>
</batch:tasklet>
</batch:step>
<!-- 發送到賬模板 -->
<batch:step id="tranInfoStep" >
<batch:tasklet transaction-manager="main_txManager" >
<batch:chunk reader="tranIntoTemplateReader" writer="noticeInfoWriter" processor="tranIntoTemplateProcessor"
commit-interval="100" >
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:flow>
<!-- 監聽用戶讀取紅包信息 -->
<bean id="redExpireDetailListener" class="com.cwenao.cc.scheduler.batch.listener.RedExpireDetailListener" >
</bean>
附錄
[IBM developerworks](http://www.ibm.com/developerworks/cn/java/j-lo-springbatch2/)
《Spring Batch in Action》
如有疑問請加公衆號(K171),如果覺得對您有幫助請 github start