Merge arbitrary number of for each output payloads mulesoft












0















I'm trying to create a flow, that takes the URI params it got called with and uses them to call another flow (the number of times the other flow is called depends on the number of URI params).



    <flow name="get:/test-config">

<set-variable value="#[message.inboundProperties['http.query.params']]" variableName="params" doc:name="Variable"/>

<!-- Iterate over the keys to retrieve each params list -->
<foreach collection="#[flowVars['params'].keySet()]" doc:name="For Each">

<!-- Iterate over the params list for each key -->
<foreach collection="#[params.getAll(payload)]" doc:name="For Each">

<logger level="WARN" message="Parameter - key: #[rootMessage], value: #[payload]" doc:name="Logger"/>

<set-variable variableName=„Id“ value="#[payload]" doc:name="Variable"/>

<logger message="Id: #[payload]" level="INFO" doc:name="Logger"/>

<http:request config-ref="HTTP_REQUEST" path=„/test1/foo“ method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName=„Id" value="#[flowVars.Id]"/>
</http:request-builder>
</http:request>

<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"Id" : flowVars.Id,
"color" : payload.*color
} ]]>
</dw:set-payload>
</dw:transform-message>

<logger message="#[payload]" level="INFO" doc:name="Logger"/>

</foreach>

</foreach>

</flow>


The flow that gets called via the HTTP Request delivers data in JSON format:



   "Id": "1",
"color": [
"blue",
"green"
]

"Id": "2",
"color": [
"yellow",
"blue"
]

"Id": "3"
...

"Id" : "4"
...


 
I'd like to filter and aggregate these outputs so the overall result looks like this:



     "Ids": [
"1",
"2"
]
"commonColor": [
"blue"
]


And at this point I'm kinda stuck as the number of data sets to merge varies and I also don't quite know how to access and compare the fields of the payload to find items with matching colors, as the payload changes with every iteration. One idea I came across was to save / append the current payload in a variable to save it for further processing, but all examples just worked with 2 or a maximum of three payloads, whereas I'm confronted with an arbitrary amount of possible payloads (and the position / number of colors also varies...).



Any ideas / help on how this problem could be solved would be very appreciated!



PS: I also came across Scatter / Gather, but I'm not quite sure if it's suitable in this case, as I don't know the number of calls / intermediary results beforehand...










share|improve this question























  • Please add more detail about what should be the expected output. You show an incomplete example and suggested there are many variations. Which ids are selected? Are the colors only the ones that appear in all responses from the HTTP request?

    – Alejandro Dobniewski
    Nov 20 '18 at 23:27
















0















I'm trying to create a flow, that takes the URI params it got called with and uses them to call another flow (the number of times the other flow is called depends on the number of URI params).



    <flow name="get:/test-config">

<set-variable value="#[message.inboundProperties['http.query.params']]" variableName="params" doc:name="Variable"/>

<!-- Iterate over the keys to retrieve each params list -->
<foreach collection="#[flowVars['params'].keySet()]" doc:name="For Each">

<!-- Iterate over the params list for each key -->
<foreach collection="#[params.getAll(payload)]" doc:name="For Each">

<logger level="WARN" message="Parameter - key: #[rootMessage], value: #[payload]" doc:name="Logger"/>

<set-variable variableName=„Id“ value="#[payload]" doc:name="Variable"/>

<logger message="Id: #[payload]" level="INFO" doc:name="Logger"/>

<http:request config-ref="HTTP_REQUEST" path=„/test1/foo“ method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName=„Id" value="#[flowVars.Id]"/>
</http:request-builder>
</http:request>

<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"Id" : flowVars.Id,
"color" : payload.*color
} ]]>
</dw:set-payload>
</dw:transform-message>

<logger message="#[payload]" level="INFO" doc:name="Logger"/>

</foreach>

</foreach>

</flow>


The flow that gets called via the HTTP Request delivers data in JSON format:



   "Id": "1",
"color": [
"blue",
"green"
]

"Id": "2",
"color": [
"yellow",
"blue"
]

"Id": "3"
...

"Id" : "4"
...


 
I'd like to filter and aggregate these outputs so the overall result looks like this:



     "Ids": [
"1",
"2"
]
"commonColor": [
"blue"
]


And at this point I'm kinda stuck as the number of data sets to merge varies and I also don't quite know how to access and compare the fields of the payload to find items with matching colors, as the payload changes with every iteration. One idea I came across was to save / append the current payload in a variable to save it for further processing, but all examples just worked with 2 or a maximum of three payloads, whereas I'm confronted with an arbitrary amount of possible payloads (and the position / number of colors also varies...).



Any ideas / help on how this problem could be solved would be very appreciated!



PS: I also came across Scatter / Gather, but I'm not quite sure if it's suitable in this case, as I don't know the number of calls / intermediary results beforehand...










share|improve this question























  • Please add more detail about what should be the expected output. You show an incomplete example and suggested there are many variations. Which ids are selected? Are the colors only the ones that appear in all responses from the HTTP request?

    – Alejandro Dobniewski
    Nov 20 '18 at 23:27














0












0








0








I'm trying to create a flow, that takes the URI params it got called with and uses them to call another flow (the number of times the other flow is called depends on the number of URI params).



    <flow name="get:/test-config">

<set-variable value="#[message.inboundProperties['http.query.params']]" variableName="params" doc:name="Variable"/>

<!-- Iterate over the keys to retrieve each params list -->
<foreach collection="#[flowVars['params'].keySet()]" doc:name="For Each">

<!-- Iterate over the params list for each key -->
<foreach collection="#[params.getAll(payload)]" doc:name="For Each">

<logger level="WARN" message="Parameter - key: #[rootMessage], value: #[payload]" doc:name="Logger"/>

<set-variable variableName=„Id“ value="#[payload]" doc:name="Variable"/>

<logger message="Id: #[payload]" level="INFO" doc:name="Logger"/>

<http:request config-ref="HTTP_REQUEST" path=„/test1/foo“ method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName=„Id" value="#[flowVars.Id]"/>
</http:request-builder>
</http:request>

<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"Id" : flowVars.Id,
"color" : payload.*color
} ]]>
</dw:set-payload>
</dw:transform-message>

<logger message="#[payload]" level="INFO" doc:name="Logger"/>

</foreach>

</foreach>

</flow>


The flow that gets called via the HTTP Request delivers data in JSON format:



   "Id": "1",
"color": [
"blue",
"green"
]

"Id": "2",
"color": [
"yellow",
"blue"
]

"Id": "3"
...

"Id" : "4"
...


 
I'd like to filter and aggregate these outputs so the overall result looks like this:



     "Ids": [
"1",
"2"
]
"commonColor": [
"blue"
]


And at this point I'm kinda stuck as the number of data sets to merge varies and I also don't quite know how to access and compare the fields of the payload to find items with matching colors, as the payload changes with every iteration. One idea I came across was to save / append the current payload in a variable to save it for further processing, but all examples just worked with 2 or a maximum of three payloads, whereas I'm confronted with an arbitrary amount of possible payloads (and the position / number of colors also varies...).



Any ideas / help on how this problem could be solved would be very appreciated!



PS: I also came across Scatter / Gather, but I'm not quite sure if it's suitable in this case, as I don't know the number of calls / intermediary results beforehand...










share|improve this question














I'm trying to create a flow, that takes the URI params it got called with and uses them to call another flow (the number of times the other flow is called depends on the number of URI params).



    <flow name="get:/test-config">

<set-variable value="#[message.inboundProperties['http.query.params']]" variableName="params" doc:name="Variable"/>

<!-- Iterate over the keys to retrieve each params list -->
<foreach collection="#[flowVars['params'].keySet()]" doc:name="For Each">

<!-- Iterate over the params list for each key -->
<foreach collection="#[params.getAll(payload)]" doc:name="For Each">

<logger level="WARN" message="Parameter - key: #[rootMessage], value: #[payload]" doc:name="Logger"/>

<set-variable variableName=„Id“ value="#[payload]" doc:name="Variable"/>

<logger message="Id: #[payload]" level="INFO" doc:name="Logger"/>

<http:request config-ref="HTTP_REQUEST" path=„/test1/foo“ method="GET" doc:name="HTTP">
<http:request-builder>
<http:query-param paramName=„Id" value="#[flowVars.Id]"/>
</http:request-builder>
</http:request>

<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"Id" : flowVars.Id,
"color" : payload.*color
} ]]>
</dw:set-payload>
</dw:transform-message>

<logger message="#[payload]" level="INFO" doc:name="Logger"/>

</foreach>

</foreach>

</flow>


The flow that gets called via the HTTP Request delivers data in JSON format:



   "Id": "1",
"color": [
"blue",
"green"
]

"Id": "2",
"color": [
"yellow",
"blue"
]

"Id": "3"
...

"Id" : "4"
...


 
I'd like to filter and aggregate these outputs so the overall result looks like this:



     "Ids": [
"1",
"2"
]
"commonColor": [
"blue"
]


And at this point I'm kinda stuck as the number of data sets to merge varies and I also don't quite know how to access and compare the fields of the payload to find items with matching colors, as the payload changes with every iteration. One idea I came across was to save / append the current payload in a variable to save it for further processing, but all examples just worked with 2 or a maximum of three payloads, whereas I'm confronted with an arbitrary amount of possible payloads (and the position / number of colors also varies...).



Any ideas / help on how this problem could be solved would be very appreciated!



PS: I also came across Scatter / Gather, but I'm not quite sure if it's suitable in this case, as I don't know the number of calls / intermediary results beforehand...







mule mule-component dataweave






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 22:09









Charlie28000Charlie28000

373




373













  • Please add more detail about what should be the expected output. You show an incomplete example and suggested there are many variations. Which ids are selected? Are the colors only the ones that appear in all responses from the HTTP request?

    – Alejandro Dobniewski
    Nov 20 '18 at 23:27



















  • Please add more detail about what should be the expected output. You show an incomplete example and suggested there are many variations. Which ids are selected? Are the colors only the ones that appear in all responses from the HTTP request?

    – Alejandro Dobniewski
    Nov 20 '18 at 23:27

















Please add more detail about what should be the expected output. You show an incomplete example and suggested there are many variations. Which ids are selected? Are the colors only the ones that appear in all responses from the HTTP request?

– Alejandro Dobniewski
Nov 20 '18 at 23:27





Please add more detail about what should be the expected output. You show an incomplete example and suggested there are many variations. Which ids are selected? Are the colors only the ones that appear in all responses from the HTTP request?

– Alejandro Dobniewski
Nov 20 '18 at 23:27












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402345%2fmerge-arbitrary-number-of-for-each-output-payloads-mulesoft%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402345%2fmerge-arbitrary-number-of-for-each-output-payloads-mulesoft%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud