我正在按计划的时间使用一条队列并对消息进行分组的路由,但是民意调查不能接收来自代理的1条消息中的更多消息,我尝试使用聚合器,但不起作用。这是使用XML Spring定义的骆驼路线的示例代码:
这是创建消息的途径:
<route id="routeAmqTesting">
<description>Route that send messages to Amq</description>
<from uri="timer:hello?period=1s"/>
<setBody>
<simple>Hello World at ${date:now:hh:mm:ss}</simple>
</setBody>
<log message="Sending message to Amq ${body}"/>
<to uri="activemq:queue:Q-TechnicalRetries"/>
</route>
这是消耗消息的路由:
<route id="routeAmqInvoker">
<description>Route that a sheduled time read the messages from amq</description>
<from uri="timer:hello2?delay=10s&repeatCount=1"/>
<log message="[${camelId}] Reading messages from broker"/>
<pollEnrich uri="activemq:queue:Q-TechnicalRetries" timeout="1000"/>
<aggregate groupExchanges="true">
<correlationExpression>
<simple>true</simple>
</correlationExpression>
<completionTimeout>
<constant>1000</constant>
</completionTimeout>
<log message="The number of exchanges is ${body.size}"/>
<log message="Exchanges: ${body}"/>
</aggregate>
</route>
日志仅显示1条消息被聚合,但在这种情况下应显示10条消息。
[nce) thread #7 - timer://hello] timeAndAttendance INFO Sending message to Amq Hello World at 10:19:35
[nce) thread #7 - timer://hello] timeAndAttendance INFO Sending message to Amq Hello World at 10:19:36
...
[d #1 - AggregateTimeoutChecker] timeAndAttendance INFO The number of exchanges is 1
[d #1 - AggregateTimeoutChecker] timeAndAttendance INFO Exchanges: List<Exchange>(1 elements)