JavaSI+观察者模式
我有一个使用spring集成的代码库
<integration-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel"
session-factory="ftpClientFactory"
filter="myCustomFilter"
auto-create-local-directory="true"
delete-remote-files="false"
remote-directory="/foo/bar"
local-directory="file:output">
<integration:poller fixed-rate="5000" max-messages-per-poll="-1"/>
</integration-ftp:inbound-channel-adapter>
<integration:channel id="ftpChannel">
<integration:queue />
</integration:channel>
<integration:service-activator id="mySA" method="handleMessage" input-channel="ftpChannel" output-channel="outputChannel" ref="myDataGetter">
<integration:poller fixed-rate="1000" max-messages-per-poll="-1"/>
</integration:service-activator>
myCustomFilter的bean运行良好,我在myDataGetter bean的handleMessage()方法中得到了过滤过的文件
到目前为止还不错。 现在在myDataGetter bean中,我根据日期进一步过滤文件,例如,轮询器会给我9个文件,但实际上它们是3个版本,仅适用于3个日期
data_file1.20130816
data_file1.20130815
data_file1.20130814
data_file2.20130816
data_file2.20130815
data_file2.20130814
data_file3.20130816
data_file3.20130815
data_file3.20130814
现在我的目标是获取最新的3个文件,即数据文件1、2和3的20130816版本。 因此,我在handleMessage方法中得到了一个逻辑构建,用于构建HashMap,其中将包含这3个文件的最新版本。它使用一种简单的逻辑来完成,即迭代数据列表,并将主题中的文件与之进行比较。经过几次迭代,我得到了HashMap构建,其中包含最新的3个文件
现在我的下一个要求是通过一个通道将这3个文件传递给下一个bean
但是,应该从通道读取数据的bean应该只在HashMap完全使用最新的3个数据文件构建时读取。 在SI中是否有什么可以做到的,以便只有在处理完所有传入数据并过滤掉一组数据后,数据才能放入下一个通道
我可以考虑让myDataGetter成为Observable,让下一个频道的bean成为observer。但它不符合SI的工作方式
有什么评论吗
# 1 楼答案
可以将
<aggregator/>
与自定义发布策略结合使用