繁体   English   中英

Spring Batch作业后触发Spring Integration Outbound适配器

[英]Triggering a Spring Integration Outbound Adapter after a Spring Batch Job

作为其在描述我的要求是几乎相同的帖子在这里。 也就是说,在完成文件生成器Spring Batch之后触发Spring Integration程序。 我主要在这里使用Spring Integration示例: XML ConfigurationTest 我观察到的是,测试程序将配置文件初始化为ClassPathXmlApplicationContext,然后根据需要设置一些值。 忽略配置,程序的症结似乎是以下四行:

final File file = new File(sourceFileName);
final Message<File> message = MessageBuilder.withPayload(file).build();
final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
inputChannel.send(message);

我想知道是否有将其移入配置文件本身的选项,所以我不必创建Message或将其从测试程序传递到MessageChannel,而是可以启动Spring批处理并观看它作业完成后,请调用出站SFTP触发器。 如果完成此操作,则我的工作大部分已经完成,因此我可以将其插入到Spring Batch作业的下一步中。

如果您注意到入站适配器的示例,则可以使用以下代码行在配置文件本身中完成所有这些操作:

<int-sftp:inbound-channel-adapter id="sftpInbondAdapter"
        channel="receiveChannel"
        session-factory="sftpSessionFactory"
        local-directory="file:${inbound.local.directory}"
        remote-directory="${inbound.remote.directory}"
        auto-create-local-directory="true"
        delete-remote-files="false"
        filename-pattern="*.*">
    <int:poller max-messages-per-poll="-1" fixed-rate="1000" />
</int-sftp:inbound-channel-adapter>

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

测试程序中,我可以执行以下操作:

PollableChannel localFileChannel = context.getBean("inboundFileChannel", PollableChannel.class);
System.out.println("Received first file message: " + localFileChannel.receive());

可能是我在这里错过了一些非常基本的东西。 我还查看了前面的文章中引用示例 ,该示例调用Tasklet,并且在Tasklet中,用户再次初始化上下文文件,这对我来说似乎不是一个好方法,因为我将要使用Spring Batch和Spring Integration配置在相同的XML中,看起来就像一个循环调用。

您可以使用消息传递网关 只需定义POJI并在与批处理作业相同的上下文中将其配置为<gateway/> 将其注入tasklet步骤中,它将调用流程。

或者,使用JobLaunchingGateway启动批处理作业,然后在网关完成后执行sftp。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM