有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我对spring批处理是新手。我正在使用远程分块,其中有一个主节点、多个从节点和ActiveMQ用于消息传递

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

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

因此,我们可以一次运行两个作业,剩余的作业将在队列中
提交两个作业时,主作业正在创建块并提交到队列,从作业正在处理

但是从奴隶到主人的确认是错误的

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    

请帮我做这个


共 (2) 个答案

  1. # 1 楼答案

    这是一篇非常古老的文章,但我认为您在这里看到的问题可能与节流限制大于maxWaitTimouts4有关

    我们所看到的是,在作业完成后,实现不会从应答队列中读取超过maxWaitTimeouts个条目。我认为这是一个错误

    另请参见我在stackoverflow上提出的问题:Remote batch job does not read all responses in afterStep method

    我也为此做了一个bug报告:https://jira.spring.io/browse/BATCH-2651并且正在创建一个PR来修复这个问题

  2. # 2 楼答案

    ChunkMessageChannelItemWriter只为一个并发步骤设计-您需要将其放在步骤范围内,以便每个作业都有自己的实例see this test case

    编辑

    其实没有,;这是行不通的——因为bean实例使用相同的回复通道,所以它们可以获得彼此的回复。我打开了一个JIRA Issue