触发器2 spring集成在不同的服务器中但具有1个相同的文件轮询文件夹

时间:2014-12-20 15:52:02

标签: java spring spring-integration

我正在使用int-file:inbound-channel-adapter来处理该文件。

我在2差异服务器中获得了2 int-file:inbound-channel-adapter但是轮询了相同的文件夹。

2个侦听器将侦听1个相同的服务器文件夹。监听器1无法处理消息,因为它已由监听器2处理。错误如下所示。

听众1: -

2014-12-20 22:15:27.608 [task-scheduler-3] DEBUG org.springframework.integration.file.FileReadingMessageSource - Added to queue: [/folder/101.txt]

2014-12-20 22:15:27.715 [task-scheduler-3] DEBUG org.springframework.integration.file.FileWritingMessageHandler - org.springframework.integration.file.FileWritingMessageHandler@502a3135 received message: [Payload=/folder/101.txt][Headers={timestamp=1419084927715, id=f5bb68b3-0eac-40a6-8fcf-8ba54fc295af}]
2014-12-20 22:15:27.724 [task-scheduler-3] INFO  org.springframework.integration.file.FileWritingMessageHandler - Failed to move file '/folder/101.txt'. Using copy and delete fallback.

听众2: -

2014-12-20 22:15:27.585 [task-scheduler-6] DEBUG org.springframework.integration.file.FileReadingMessageSource - Added to queue: [/folder/101.txt]

2014-12-20 22:15:27.711 [task-scheduler-6] DEBUG org.springframework.integration.file.FileWritingMessageHandler - org.springframework.integration.file.FileWritingMessageHandler@1447034b received message: [Payload=/folder/101.txt][Headers={timestamp=1419084927710, id=2177d3cd-fbd9-4412-98d1-48ce84874b53}]

所以我怀疑启动两个侦听器的有效负载消息都得到了该文件。但是,在监听器中的一个已经处理完文件之后,第二个监听器将无法命中错误。

部分代码如下: -

<int-file:inbound-channel-adapter id="Id1" directory="/folder" prevent-duplicates="false">
    <int:poller id="poller" fixed-rate="10000" max-messages-per-poll="1" />
</int-file:inbound-channel-adapter>

<int-file:outbound-gateway 
    request-channel="Id1" reply-channel="Id1Processing"
    directory="/folder/backup}" delete-source-files="true"/>

欣赏某人可以提供帮助。感谢。

1 个答案:

答案 0 :(得分:0)

让我猜一下:您不想在第二台服务器上处理同一文件以避免该错误。为此,您应使用FileSystemPersistentAcceptOnceFileListFilter作为filter的{​​{1}}的参考。考虑使用一些开箱即用的<int-file:inbound-channel-adapter>或实现自己的。{/ p>

相关问题