首页 > 解决方案 > Spring Batch 从 2.2 迁移到 4.x(分区作业的 XML 配置)

问题描述

我正在将带有 XML 配置的 Spring Batch 分区作业迁移到 Spring batch 4.x。我试图利用 MessageChannelPartitionHandler 的改进,它通过回复通道和数据源轮询来查找远程步骤的完成。

当我使用此配置时:

<int:channel id="partitioned.jms.requests">
            <int:dispatcher task-executor="springbatch.partitioned.jms.taskExecutor"/>    
</int:channel>
<int:channel id="partitioned.jms.reply" />

    <bean id="partitioned.jms.handler" class="org.springframework.batch.integration.partition.MessageChannelPartitionHandler">
        <property name="messagingOperations">
            <bean class="org.springframework.integration.core.MessagingTemplate">
                <property name="defaultChannel" ref="partitioned.jms.requests"/>
            </bean>
        </property>
        <property name="stepName" value="process.partitioned.step"/>        
        <property name="gridSize" value="${process.step.partitioned.gridSize}"/>        
        <property name="dataSource" ref="springbatch.repositoryDataSource" />
        <property name="pollInterval" value="${springbatch.partition.verification.interval}"/>          
    </bean>

该步骤已完成,但我在日志中看到错误。

no output-channel or replyChannel header available

我查看了该类,发现我可以向 MessageChannelPartitionHandler 类添加一个 replyChannel 属性。如果我添加以下内容:

<property name="replyChannel" ref="claim.acp.process.partitioned.jms.reply"/>      

我收到错误提示需要可轮询通道。

如何创建可轮询通道(假设来自同一个 JMS 队列)?

标签: spring-integrationspring-batch

解决方案


您需要显示其余的配置。

如果您对结果使用 DB 轮询,请将output-channeljms 出站网关上的设置为"nullChannel",通过 JMS 收到的回复将被丢弃。

或者,使用出站通道适配器(而不是网关)(以及从站上的入站通道适配器)。这样可以避免完全返回答复。

您必须设置pollRepositoryForResultstrue.

回答您的具体问题

<int:channel id="replies>
    <int:queue />
<int:channel>

推荐阅读