【问题标题】:how to write output channel from itemWriter in spring batch and spring integration?如何在spring批处理和spring集成中从itemWriter编写输出通道?
【发布时间】:2015-04-26 10:50:22
【问题描述】:

首先感谢您的关注,我结合了spring批处理和spring集成,我定义了一个工作流并从ftp适配器检索文件并发送到jobChannel,并使用spring批处理对其进行处理,我想写入输出通道并使用通道处理后,我的代码是:

     <int-ftp:outbound-gateway id="gatewayGET"
                                  local-directory-expression="'./backup/' +#remoteDirectory"
                                  session-factory="ftpSessionFactory"
                                  request-channel="toGetChannel"
                                  reply-channel="toProcessChannel"
                                  command="get"
                                  temporary-file-suffix=".writing"
                                  command-options="-P"
                                  expression="payload.remoteDirectory + '/' + payload.filename"/>
        <int:channel id="toProcessChannel">
            <int:interceptors>
                <int:wire-tap channel="logger2"/>
            </int:interceptors>
        </int:channel>
    <int:channel id="outboundJobRequestChannel"/>
    <int:channel id="replyJobChannel"/>
   <service-activator input-channel="jobLaunchReplyChannel"/>
 <int:transformer input-channel="toProcessChannel" output-channel="outboundJobRequestChannel">
        <bean class="ir.isc.macna.configuration.FileMessageToJobRequest">
            <property name="fileParameterName" value="fileName"/>
        </bean>
    </int:transformer>
    <batch-int:job-launching-gateway request-channel="outboundJobRequestChannel"
                                     reply-channel="jobLaunchReplyChannel"/>

我的作家代码是:

@Component
@StepScope
public class MacnaFileWriter implements ChunkMessageChannelItemWriter<FileInfo> {

    @Autowired
    @Qualifier("replyJobChannel")
    private MessageChannel messageChannel;
    @Override
    public void write(List<? extends FileInfo> list) throws Exception {

       // send Message to replyJobChannel channel with Send method
    }
}

并使用 ftp 适配器在服务器上写入文件:

<int-ftp:outbound-gateway session-factory="ftpSessionFactory"
                              request-channel="replyJob"
                              command="mput"
                              auto-create-directory="true"
                              expression="payload"
                              remote-directory-expression="payload.remoteDirectory + '/' + payload.filename + '.out'"
                              reply-channel="output"/>

这是运行批处理作业并使用结果的标准方式吗?

【问题讨论】:

    标签: spring ftp spring-integration


    【解决方案1】:

    MessageChannelsend 方法。为此,您可以使用MessageBuilder 为您的payload 创建一个Message&lt;?&gt;

    因为它只是一个&lt;channel&gt;,所以与任何其他MessageChannel 消费没有区别。标准的方式定义一个消费者是这样的:

    <service-activator input-channel="jobLaunchReplyChannel"/>
    

    但是,当此通道特定于来自&lt;batch-int:job-launching-gateway&gt;JobLaunchingGateway 类)的结果时,尚不清楚为什么要将消息发送到jobLaunchReplyChannel

    jobExecution = this.jobLaunchingMessageHandler.launch(jobLaunchRequest);
    

    所以,jobExecution 被发送到jobLaunchReplyChannel

    请参阅 Spring Batch Integration 文档。

    也许您需要AsyncItemWriterChunkMessageChannelItemWriter

    【讨论】:

    • 感谢@Artem 的回复,我想从 ftp 服务器检索文件并运行批处理作业,然后再次使用 mput commad 在 ftp 服务器上写入文件,感谢您帮助我理解 jobLaunchReplyChannel 就是这样它是如何工作的,我需要其他渠道来发送消息,现在我将更新帖子。
    • 是的,看起来不错。正如我在回答中所说,您真的可以将每个项目发送给MessageChannel。有关更多信息,请参阅此问题:stackoverflow.com/questions/24033484/…
    • 非常感谢您关注并回答我的问题。
    猜你喜欢
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2022-12-05
    • 2021-02-10
    • 2020-12-15
    相关资源
    最近更新 更多