我收到来自activeMQ的两条JMS消息
<flow name="clientoneFlow1" doc:name="clientoneFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" path="client1" doc:name="HTTP"/>
<component class="SalesOrder" doc:name="Java"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<jms:outbound-endpoint queue="ReadOrder1" connector-ref="Active_MQ" doc:name="JMS">
<jms:object-to-jmsmessage-transformer doc:name="Object to JMSMessage"/>
</jms:outbound-endpoint>
</flow>
<flow name="clienttwoFlow1" doc:name="clienttwoFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" path="client2" doc:name="HTTP"/>
<component class="SalesOrder2" doc:name="Java"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<jms:outbound-endpoint queue="ReadOrder1" connector-ref="Active_MQ" doc:name="JMS">
<jms:object-to-jmsmessage-transformer doc:name="Object to JMSMessage"/>
</jms:outbound-endpoint>
</flow>
<flow name="integration-flow" doc:name="integration-Flow1" processingStrategy="synchronous">
<jms:inbound-endpoint queue="ReadOrder1" connector-ref="Active_MQ" doc:name="JMS"/>
<vm:outbound-endpoint exchange-pattern="request-response" path="vm" doc:name="VM"/>
<logger message="ending paylaod = #[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="integration-flow2" doc:name="integration-Flow2">
<vm:inbound-endpoint exchange-pattern="request-response" path="vm" doc:name="VM"/>
<collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>
</flow>
如何汇总收到的消息?我正在使用集合聚合器,我不断收到消息= 未设置关联组大小,但正在使用关联聚合器。消息按原样转发
消息是JSON [{“salesOrderId”:“00001-2-3”,“saleName”:“汽车销售”,“状态”:“处理”}]
答案 0 :(得分:1)
我在流程中看到了一些问题..在流 clientoneFlow1 和 clienttwoFlow1 中,您正在使用http入站端点并单独点击网址以启动流量调度消息到队列=“ReadOrder1”..
但是,只要消息通过其中一个流传递到queue =“ReadOrder1”, integration-flow 就会开始,并且消息将再次发送到 integration-flow2 collection-aggregator 收到它并且它不会等待其他流来获取消息(因为您需要点击其他流的url来启动它)。 ..
所以..在这里你可以使流 clientoneFlow1 和 clienttwoFlow1 几乎并行执行并将消息发送到集合聚合器几乎在同一时间..
所以..通过使用分散和收集组件可以实现它的一种方法,你不需要那里的集合 - 聚合器 ..
来自所有流的所有消息将在流程结束时自动汇总..
例如......在这里你可以做到以下几点: -
<flow name="fork" doc:name="fork">
<http:inbound-endpoint host="localhost" port="8090" path="scattergather" exchange-pattern="request-response" doc:name="HTTP"/>
<scatter-gather timeout="6000">
<!-- Calling clientoneFlow1-->
<flow-ref name="clientoneFlow1" doc:name="Flow Reference"/>
<!-- Calling clienttwoFlow1-->
<flow-ref name="clienttwoFlow1" doc:name="Flow Reference"/>
</scatter-gather>
<logger level="INFO" message="Combined Payload: #[message.payload]" doc:name="Logger"/>
<logger level="INFO" message="Payload1 of clientoneFlow1 : #[message.payload[0]] and clienttwoFlow1: #[message.payload[1]] " doc:name="Logger"/>
</flow>
<flow name="clientoneFlow1" doc:name="clientoneFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" path="client1" doc:name="HTTP"/>
<component class="SalesOrder" doc:name="Java"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
<flow name="clienttwoFlow1" doc:name="clienttwoFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" path="client2" doc:name="HTTP"/>
<component class="SalesOrder2" doc:name="Java"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</flow>
现在,这是从两个流程中实现组合有效负载的最简单方法,而不会让它变得如此复杂。