首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SI +观察者模式

SI +观察者模式
EN

Stack Overflow用户
提问于 2013-08-17 00:21:21
回答 1查看 97关注 0票数 1

我有一个使用spring集成的代码库。

代码语言:javascript
复制
<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个版本。

代码语言:javascript
复制
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个文件,即data_file1,2的20130816版本和3。所以我在handleMessage方法中建立了一个逻辑构建HashMap,它将包含这3个文件的最新版本。它用一种天真的逻辑来迭代数据列表,并将主题中的文件与其进行比较。经过几次迭代,我得到了包含最新3个文件的HashMap构建。

现在,我的下一个要求是通过通道将这3个文件传递给下一个bean。

但是,应该从通道读取数据的bean应该只在HashMap完全使用最新的3个数据文件构建时才读取。在SI中有什么可以做的,以便只有在处理所有传入数据并从中过滤出一组数据后,才将数据放入下一个通道?

我可以考虑让myDataGetter具有同样的可观察性,并作为观察者作为下一个通道的bean。但它不适合在SI中如何做事情。

有什么意见吗?

EN

回答 1

Stack Overflow用户

发布于 2013-08-17 01:48:34

您可以将<aggregator/>与自定义发布策略一起使用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18277909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档