[英]Spring Integration Aggregator - lost messages
我想收集一些消息(比如说10条消息),并将它们作为列表传递给服务激活器,而不是一一传递。
上下文:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=...>
<int:channel id="ch.http.in"/>
<int:channel id="ch.http.trans"/>
<int:channel id="ch.http.aggr"/>
<int-http:inbound-channel-adapter path="test" channel="ch.http.in"/>
<int:map-to-object-transformer input-channel="ch.http.in" output-channel="ch.http.trans" type="demo.Req"/>
<int:aggregator
input-channel="ch.http.trans"
output-channel="ch.http.aggr"
release-strategy-expression="size() == 10"
correlation-strategy-expression="headers['id']"
ref="aggr" method="add"/>
<int:service-activator ref="srv" method="httpTest" input-channel="ch.http.aggr"/>
<bean id="srv" class="demo.IntService"/>
<bean id="aggr" class="demo.HttpAggregator"/>
</beans>
聚集器:
public class HttpAggregator{
public List<Req> add(List<Req> reqs) {
System.out.println(reqs);
return reqs;
}
}
服务:
public class IntService {
public void httpTest(Req msg){
System.out.println(msg);
}
}
Req只是一个POJO。
问题是永远不会调用聚合器方法。 没有聚集器,消息将毫无问题地传递到服务激活器。 使用Spring Integration 3.0.2.RELEASE(Spring Boot 1.0.2.RELEASE)
编辑:当我将correlation-strategy-expression="headers['id']"
更改为correlation-strategy-expression="payload.id"
(Req对象具有属性ID)时,当我为每个块传递不同的ID(例如,对于前10个,id = 1;对于接下来的10,id 2 ...)看起来这就是关联策略的工作方式。 我怎样才能通过? 我只想限制聚合列表的大小。
对; 您必须关联某些东西; 使用headers ['id']最终将导致1件物品的分组,这将永远无法满足发布策略。
对于像您这样的简单用例,请在文字上进行关联-例如, correlation-expression="'foo'"
并设置expire-groups-on-completion="true"
。 这会在发布后重置该组,因此可以在下一条消息上开始一个新的(具有相同的关联ID)。
如果要在超时后释放部分组,则需要一个MessageGroupStoreReaper
。 或者,如果您可以升级到4.0.x,则聚合器现在具有group-timeout
(或group-timeout-expression
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.