【发布时间】:2011-10-21 00:00:42
【问题描述】:
在我的 Spring Integration 驱动项目中,我有一个拆分器和有效负载路由器,用于将我的数据发送到各种转换器。然后将新的“转换”对象传递回聚合器并进行处理。
现在我想拆分我的聚合结果,以便正确保存它们,因为我需要将一些对象路由到单独的出站通道适配器。为此,我在聚合器之后添加了第二个拆分器;但似乎只有聚合集合中的第一个元素会传递给路由器。
这是我目前的流程:
<splitter ref="articleContentExtractor" />
<!-- This router works exactly as expected -->
<payload-type-router>
... routing to various transformers ...
... results are sent to articleOutAggregateChannel ...
</payload-type-router>
<aggregator ref="articleAggregator" />
<splitter />
<!-- This is where it seems to go wrong, the second
splitter returns only the first object in the collection -->
<payload-type-router resolution-required="true">
<mapping type="x.y.z.AbstractContent" channel="contentOutChannel" />
<mapping type="x.y.z.Staff" channel="staffOutChannel" />
</payload-type-router>
<outbound-channel-adapter id="contentSaveService" ref="contentExporter"
method="persist" channel="contentOutChannel" />
<outbound-channel-adapter id="staffSaveService" ref="staffExporter"
method="persist" channel="staffOutChannel" />
还有我的聚合器代码:
@Aggregator
public List<? super BaseObject> compileArticle(List<? super BaseObject> parts) {
// Search for the required objects for referencing
Iterator<? super BaseObject> it = parts.iterator();
Article article = null;
List<Staff> authors = new ArrayList<Staff>();
while (it.hasNext()) {
Object part = it.next();
if (part instanceof Article) {
article = (Article)part;
}
else if (part instanceof Staff) {
authors.add((Staff)part);
}
}
// Apply references
article.setAuthors(authors);
return parts;
}
我做错了什么?我是否正确使用我的聚合器?
注意:如果我完全删除聚合器和第二个拆分器,则流程的其余部分可以完美运行。
【问题讨论】:
-
它可以工作(即没有错误),但第二个拆分器只返回集合中的第一个元素
-
我已经编辑了我的问题,以便更容易理解我的问题
-
是的,我调试时返回的对象部分包含整个集合。例如,如果我的parts 对象中有{Article, Staff, Staff},我的payload-type-router 只用Article 对象触发一次,Staff 对象就完全丢失了
标签: spring spring-integration aggregator