Andre Coetzee
Andre Coetzee

Reputation: 1310

Getting JMS Correlation Id after aggregation in mule

I have two JMS outbound messages that are received in a scatter gather to aggregate the two messages from the clients. then i need to use a splitter to split the messages and then send them one by one to another flow via 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>

but after the splitter the correlation Ids of the two clients have disappeared and assigned the same correlation Id. How can i retrieve the correlation Ids after the splitter? and in the validation flow consume the messages according to correlationId

Upvotes: 2

Views: 793

Answers (2)

V&#237;ctor Romero
V&#237;ctor Romero

Reputation: 5115

If you use an expression splitter you will use the list of payloads to split, and therefore a new MuleEvent on each splitted branch.

If you use a collection splitter, you'll use the EventToMessageSequenceSplittingStrategy, that will handle correctly the split of a MessageCollection.

Therefor, replace the splitter with a collection-splitter.

Upvotes: 1

Anirban Sen Chowdhary
Anirban Sen Chowdhary

Reputation: 8311

You dont need a splitter to split a message after scatter-gather ....

After scatter-gather the message is automatically a combined and messages can be extracted in following form :- #[message.payload[0]] and #[message.payload[1]] example :-

<logger level="INFO"  message="Payload1 of clientoneFlow1 : #[message.payload[0]] and clienttwoFlow1: #[message.payload[1]] " doc:name="Logger"/>

So yo can remove the splitter and try

Upvotes: 1

Related Questions