一文件读取后停止文件入站通道适配器

一文件读取后停止文件入站通道适配器

本文介绍了一文件读取后停止文件入站通道适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序使用 Spring 集成 file:inbound-channel-adapter 轮询目录以在文件被放置在那里时进行侦听.Spring Integration 然后启动一个 Spring Batch 作业,将要处理的文件的路径和名称交给作业.

显然,即使文件已被 Spring Batch 作业处理,文件轮询器仍会继续运行.因此,Spring 上下文保持打开状态,应用程序不会终止.有没有办法以编程方式或通过配置(优选)在读取一个文件后停止轮询器?

谢谢

解决方案

您可以在轮询器上使用 FireOnceTrigger,或者在 这个答案.

要以编程方式停止适配器,close() 上下文,或调用 adapter.stop()(@Autowire 适配器作为SourcePollingChannelAdapter.或者使用 <control-bus/> 并发送带有有效载荷 "adapterId.stop()" 的消息.>

Our application uses a Spring Integration file:inbound-channel-adapter to poll a directory to listen to when a file is dropped there. Spring Integration then starts a Spring Batch job, handing over to the job the path and name of the file to process.

Obviously, the file poller continues to run even after a file has been processed by the Spring Batch job. So, the Spring context remains open and the application does not terminate. Is there a way, programatically or through configuration (preferable), to stop the poller after one file has been read?

Thanks

解决方案

You can use a FireOnceTrigger on the poller, or one of the techniques described in addition to that, in this answer.

To programmatically stop the adapter, close() the context, or call adapter.stop() (@Autowire the adapter as a SourcePollingChannelAdapter. Or use a <control-bus/> and send a message with payload "adapterId.stop()".

这篇关于一文件读取后停止文件入站通道适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:48