Spring batch Partitioning with multiple steps in parallel?

前提是你 提交于 2019-12-18 13:40:14

问题


I have implemented spring batch partitioning for a single steps where a master step delegates its work to several slave threads which than gets executed in parallel. As shown in following image.(Reference Spring docs)

Now what if I have multiple steps which are to be executed in parallel? How to configure them in batch configuration? My current configuration is
 <batch:job id="myJob" restartable="true" job-repository="jobRepository" >
        <batch:listeners>
            <batch:listener ref="myJoblistener"></batch:listener>
        </batch:listeners>

        <batch:step id="my-master-step">
            <batch:partition step="my-step" partitioner="my-step-partitioner" handler="my-partitioner-handler">
            </batch:partition>
        </batch:step>
    </batch:job>

    <batch:step id="my-step" >
        <batch:tasklet ref="myTasklet" transaction-manager="transactionManager" >
        </batch:tasklet>
        <batch:listeners>
            <batch:listener ref="myStepListener"></batch:listener>
        </batch:listeners> 
    </batch:step>

My architecture diagrams should be like following image:

I am not sure even if it is possible using spring batch.Any ideas or I am way over my head to implement it.Thank you.


回答1:


You can try the following.

 <batch:job id="myJob" restartable="true" job-repository="jobRepository" >
        <batch:listeners>
            <batch:listener ref="myJoblistener"></batch:listener>
        </batch:listeners>

        <batch:step id="my-master-step">
            <batch:partition step="my-step" partitioner="my-step-partitioner" handler="my-partitioner-handler">
            </batch:partition>
        </batch:step>
    </batch:job>

    <batch:step id="my-step" >
        <batch:job ref="MyChildJob" job-launcher="jobLauncher"
                job-parameters-extractor="jobParametersExtractor" />
        <batch:listeners>
            <batch:listener ref="myStepListener"></batch:listener>
        </batch:listeners> 
    </batch:step>

    <batch:job id="MyChildJob" restartable="false"
        xmlns="http://www.springframework.org/schema/batch">
        <batch:step id="MyChildStep1" next="MyChildStep2">
            <batch:tasklet ref="MyChildStep1Tasklet" transaction-manager="transactionManager" >
            </batch:tasklet>
        </batch:step>

        <batch:step id="MyChildStep2" next="MyChildStep3">
            <batch:tasklet ref="MyChildStep2Tasklet" transaction-manager="transactionManager" >
            </batch:tasklet>
        </batch:step>

        <batch:step id="MyChildStep3">
            <batch:tasklet ref="MyChildStep3Tasklet" transaction-manager="transactionManager" >
            </batch:tasklet>
        </batch:step>

    </batch:job>



回答2:


I had similar requirement and solved it using below requirement

<batch:job id="cycleJob">
        <batch:step id="zStep" next="gStep">
            <batch:partition partitioner="zPartitioner">
                <batch:step>
                    <batch:tasklet throttle-limit="1">
                        <batch:chunk processor="itemProcessor" reader="zReader" writer="itemWriter" commit-interval="1">
                        </batch:chunk>
                    </batch:tasklet>
                </batch:step>
                <batch:handler task-executor="taskExecutor" grid-size="${maxThreads}" />
            </batch:partition>
        </batch:step>
        <batch:step id="gStep" parent="zStep" next="yStep">
            <batch:partition partitioner="gPartitioner">
                <batch:step>
                    <batch:tasklet throttle-limit="1">
                        <batch:chunk processor="itemProcessor" reader="gReader" writer="itemWriter" commit-interval="1">
                        </batch:chunk>
                    </batch:tasklet>
                </batch:step>
                <batch:handler task-executor="taskExecutor" grid-size="${maxThreads}" />
            </batch:partition>
        </batch:step>
</batch:job>


来源:https://stackoverflow.com/questions/23357024/spring-batch-partitioning-with-multiple-steps-in-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!