【发布时间】:2016-01-18 16:33:09
【问题描述】:
如何在不同的线程中处理文件?
有一个 /local 目录,其中文件正在通过其他方式放置,并且具有相同名称的新文件替换旧文件。 我想将文件从 /local 移动到 /processing 目录并激活一些服务。在过滤器链的末尾,清理任务将从/处理中删除文件。 我让它一个接一个地工作,但处理需要几分钟,所以我想
添加多线程:即同时移动和处理多个文件。
如果有一个文件尚未处理,比如“File1.abc”,并且该文件的新版本已放入 /local,则无需使用旧版本文件处理旧消息。 IE。消息应该只针对文件从 /local 移动到 /processing 时的版本发送
我正在尝试这样的事情:
<file:inbound-channel-adapter channel="processingChannel"
directory="#{localDir}"
prevent-duplicates="false" filter="acceptAllFileListFilter">
<int:poller fixed-rate="20" max-messages-per-poll="3" task-executor="executor"/>
</file:inbound-channel-adapter>
<task:executor id="executor" pool-size="3" queue-capacity="0" rejection-policy="ABORT"/>
<file:outbound-gateway request-channel="processingChannel" reply-channel="serviceChannel"
directory="#{processing}"
auto-create-directory="true"
filename-generator-expression="payload.name + '_' + { T(java.lang.System).currentTimeMillis()}"
delete-source-files="true"
mode="FAIL" />
<int:service-activator input-channel="serviceChannel" output-channel="furtherChannels"
ref="someService" method="process">
</int:service-activator>
<bean id="someService" class="com.dot.SomeService"/>
但它不起作用,我不知道如何解决它。我尝试了不同的方法,但总是会出现错误,例如为已删除的文件或其他一些问题生成消息。任务本身似乎很简单。如何使文件在 3 个线程中处理并仅为文件的实际版本发送消息?轮询消费者可能有问题,但入站适配器仅用于此消费者,对吧?
【问题讨论】:
标签: multithreading spring-integration