我的需求。是轮询一个指定的时间间隔,例如10分钟的目录。如果一个特定扩展名的文件在目录中找到* .xml,那么它只是消耗(即选择和删除)该文件,并在指定的时间(例如10分钟)之后打印其他名称,然后发送邮件该文件没有被挑选(即消耗)或文件没有来。使用Spring集成轮询文件时的问题
有2个选项,我可以通过Spring集成或Core Java的WatchService来完成。以下是我一直写到现在的Spring Integration代码:
<int:channel id="fileChannel" />
<int:channel id="processedFileChannel" />
<context:property-placeholder location="localProps.properties" />
<int:poller default="true" fixed-rate="10000" id="poller"></int:poller>
<int-file:inbound-channel-adapter
directory="file:${inbound.folder}" channel="fileChannel"
filename-pattern="*.xml" />
<int:service-activator input-channel="fileChannel"
ref="fileHandlerService" method="processFile" output-channel="processedFileChannel"/>
<bean id="fileHandlerService" class="com.practice.cmrs.springintegration.Poll" />
以上代码已成功地针对特定文件模式轮询文件夹。现在我有两件事要做:
1)停止轮询后特定的时间间隔(可配置)说10分钟。
2)检查文件夹中是否有特定扩展名的文件...如果文件存在(它会消耗然后删除),否则它会向一群人发送电子邮件(电子邮件部分已完成。 )
请帮我在上述2点。
请问我能举一个简单的例子吗? ....我也没有从网上获得任何例子......所以它变得困难......一个例子会有帮助。 – sid
可以以某种方式使用cron表达式来完成这项工作吗? – sid
不是只有一个,但可以在'CompoundTriggerAdvice' [javadocs here]中使用两个cron触发器(http://docs.spring.io/spring-integration/docs/5.0.0.BUILD-SNAPSHOT/reference/ HTML /消息通道-section.html#_compoundtriggeradvice)。 –