如何为任务执行程序中运行的多个作业配置远程分块

如何为任务执行程序中运行的多个作业配置远程分块

本文介绍了SPRING BATCH:如何为任务执行程序中运行的多个作业配置远程分块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是春季批处理的新手.我使用的是远程分块,其中有一个master,多个slave和ActiveMQ进行消息传递.

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

大师有一个工作和一个工作启动器,而工作启动器有一个任务执行器,它具有以下配置
<task:executor id="batchJobExecutor" pool-size="2"queue-capacity="100" /> .
块配置为

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

请帮助我.

推荐答案

ChunkMessageChannelItemWriter仅用于一个并发步骤-您需要将其放在步骤作用域中,以便每个作业都有自己的实例-查看此测试案例

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

编辑

实际上,没有;那是行不通的-由于Bean实例使用相同的回复通道,因此它们可以获取彼此的回复.我打开了 JIRA问题.

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.

这篇关于SPRING BATCH:如何为任务执行程序中运行的多个作业配置远程分块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:05