Reputation: 11
I am trying to aggregate data from two tables in mule. I am using Scatter-Gather flow control to achieve this. I am able to see the data in debugger but not sure how can I combine this into a single format
payload[0]= [[{"gender":"M","dob":"1974-11-23",
"last_name":"Harding","first_name":"Ezekiel"}],
payload[1]= [{"role":"Sr. Developer"}]]
What I want to create is
payload = [[{"gender":"M","dob":"1974-11-23",
"last_name":"Harding","first_name":"Ezekiel",
"role":"Sr. Developer}]
Upvotes: 1
Views: 1097
Reputation: 61
Using CustomAggregationStratergy will be clean approach for this.
http://www.mulesoft.org/documentation/display/current/Scatter-Gather
Upvotes: 1
Reputation: 5115
If understood correctly, there is one transformer to do exactly what you need. It is the:
<combine-collections-transformer />
Upvotes: 4
Reputation: 181
Both payload[0] and payload[1] are Hashmaps. You can use putAll to append one to another
<expression-component doc:name="Expression"><![CDATA[payload[0].putAll(payload[1]);payload=payload[0]]]></expression-component>
Result will be:
{last_name=Harding, role=Sr. Developer, gender=M, first_name=Ezekiel, dob=1974-11-23}
Upvotes: 1
Reputation: 8311
The don't think there is a problem in getting combined payload after scatter gather...
If you use #[message.payload]
you will be getting combined payload, If you want to combine both the payload in a single line you can use Expression and
if you use #[message.payload[0]]
and #[message.payload[1]]
you will get payload for the 2 tables separately
EDIT :-
How about doing this :- <expression-transformer doc:name="Expression" expression="#[expression=payload[0].toString()+',' + payload[1].toString()]"/>
Upvotes: 0