我有两个在分散集合中收到的JMS出站消息,用于聚合来自客户端的两条消息。那么我需要使用拆分器来拆分消息,然后通过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"/>
<set-property propertyName="MULE_CORRELATION_ID" value="clientOne" doc:name="Property"/>
<set-property propertyName="MULE_CORRELATION_SEQUENCE" value="1" doc:name="Property"/>
<jms:outbound-endpoint queue="client1.publish" 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"/>
<set-property propertyName="MULE_CORRELATION_ID" value="clientTwo" doc:name="Property"/>
<set-property propertyName="MULE_CORRELATION_SEQUENCE" value="2" doc:name="Property"/>
<jms:outbound-endpoint queue="client2.publish" connector-ref="Active_MQ" doc:name="JMS">
<jms:object-to-jmsmessage-transformer doc:name="Object to JMSMessage"/>
</jms:outbound-endpoint>
</flow>
<flow name="integration-internetsolutionsFlow1" doc:name="integration-internetsolutionsFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="esb"/>
<scatter-gather doc:name="Scatter-Gather">
<processor-chain>
<flow-ref name="clientoneFlow1" doc:name="Flow Reference"/>
<logger message="Client One: #[message.correlationSequence]" level="INFO" doc:name="Logger"/>
</processor-chain>
<processor-chain>
<flow-ref name="clienttwoFlow1" doc:name="Flow Reference"/>
<logger message="Client Two: #[message.correlationSequence]" level="INFO" doc:name="Logger"/>
</processor-chain>
</scatter-gather>
<logger level="INFO" message="Combined Payload: #[message.payload]" doc:name="Logger"/>
<splitter enableCorrelation="ALWAYS" expression="#[payload]" doc:name="Splitter"/>
<logger message="after splitter = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="Corr after splitter = #[message.correlationId] and group = #[message.correlationGroupSize]" level="INFO" doc:name="Logger"/>
<jms:outbound-endpoint queue="validation.queue" doc:name="JMS"/>
</flow>
<flow name="validateFlow1" doc:name="validateFlow1">
<jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="validation.queue"/>
<logger message="splinter payload = #[payload]" level="INFO" doc:name="Logger"/>
<logger message="splitter corr Id = #[message.correlationId]" level="INFO" doc:name="Logger"/>
</flow>
但是在拆分器之后,两个客户端的相关ID已经消失并分配了相同的相关ID。如何在拆分器后检索相关ID?并且在验证流程中根据correlationId消耗消息
答案 0 :(得分:1)
在分散 - 聚集之后,您不需要拆分器来拆分消息....
在分散 - 聚集之后,消息会自动合并,并且可以按以下形式提取消息: -
#[message.payload[0]]
和#[message.payload[1]]
例如: -
<logger level="INFO" message="Payload1 of clientoneFlow1 : #[message.payload[0]] and clienttwoFlow1: #[message.payload[1]] " doc:name="Logger"/>
所以你可以删除拆分器并尝试
答案 1 :(得分:1)
如果使用表达式拆分器,则将使用有效负载列表进行拆分,从而在每个拆分的分支上使用新的MuleEvent。
如果你使用收集拆分器,你将使用EventToMessageSequenceSplittingStrategy,它将正确处理MessageCollection的拆分。
因此,将拆分器替换为收集拆分器。