SPRING BATCH : How to configure remote chunking for multiple jobs running in a task executor

时光毁灭记忆、已成空白 提交于 2019-12-11 06:12:45

问题


I am new to spring batch processing. I am using remote chunking where there is a master , multiple slaves and ActiveMQ for messaging.

Master has a job and a job launcher and the job launcher has a task-executor which is having following configuration
<task:executor id="batchJobExecutor" pool-size="2"queue-capacity="100" />.
Chunk configuration is

<bean id="chunkWriter"
    class="org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter" scope="step">
    <property name="messagingOperations" ref="messagingGateway" />
    <property name="replyChannel" ref="replies" />
    <property name="throttleLimit" value="50" />
    <property name="maxWaitTimeouts" value="60000" />
</bean>

<bean id="chunkHandler"
    class="org.springframework.batch.integration.chunk.RemoteChunkHandlerFactoryBean">
    <property name="chunkWriter" ref="chunkWriter" />
    <property name="step" ref="someJobId" />
</bean>

<integration:service-activator
    input-channel="requests" output-channel="replies" ref="chunkHandler" />

So we are allowed to run two jobs at a time and the remaining jobs will be in the queue.
When two jobs are submitted Master is creating the chunk and submitting to the queue and slave is processing.

But the acknowledgment from the slave to master is giving error

java.lang.IllegalStateException: Message contained wrong job instance id [9331] should have been [9332].
at org.springframework.util.Assert.state(Assert.java:385) ~[Assert.class:4.1.6.RELEASE]
at org.springframework.batch.integration.chunk.ChunkMessageChannelItemWriter.getNextResult    

Please help me with this.


回答1:


The ChunkMessageChannelItemWriter is only designed for one concurrent step - you need to put it in step scope so each job gets its own instance - see this test case

EDIT

Actually, no; that won't work - since the bean instances are using the same reply channel, they could get each other's replies. I opened a JIRA Issue.




回答2:


This is a very old post, but I think the issue you see here might be related to the throttle limit being larger than the maxWaitTimouts value 4.

What we have seen is that the implementation will not read more than maxWaitTimeouts entries from the reply queue after the job finished. I think this is a bug.

See also the question I asked on stackoverflow here : Remote batch job does not read all responses in afterStep method

I made a bug report for this as well: https://jira.spring.io/browse/BATCH-2651 and am creating a PR to fix the issue.



来源:https://stackoverflow.com/questions/37332048/spring-batch-how-to-configure-remote-chunking-for-multiple-jobs-running-in-a-t

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