We have 2 APIs which are passing JSON responses as follows
Now we need to pass the response by aggregating these responses as a single response.
Okay, We can do this by using the WSO2 Aggregrate mediator in WSO2 ESB.
The Aggregate mediator implements the Message Aggregator enterprise integration pattern and aggregates the response messages for messages that were split by the Clone or Iterate mediator and sent using the Send mediator.
The Syntax for Aggregate Mediator in WSO2
So I have created three APIs. Two for the calling endpoints and the third one for aggregate both responses.
API One.
{ "name": "Harshana", "address": "Warakapola", "vehicleNo": "BGP 3417" }
{ "name": "madusanka", "address": "colombo", "vehicleNo": "BEG 8765" }
Now we need to pass the response by aggregating these responses as a single response.
{ "response1": { "hAddress": "colombo", "name": "madusanka", "vehicle": "BEG 8765" }, "response2": { "hAddress": "Warakapola", "name": "Harshana", "vehicle": "BGP 3417" } }
Okay, We can do this by using the WSO2 Aggregrate mediator in WSO2 ESB.
The Aggregate mediator implements the Message Aggregator enterprise integration pattern and aggregates the response messages for messages that were split by the Clone or Iterate mediator and sent using the Send mediator.
The Syntax for Aggregate Mediator in WSO2
<aggregate>
<correlateOn expression=
"xpath"
/>?
<completeCondition [timeout=
"time-in-seconds"
]>
<messageCount min=
"int-min"
max=
"int-max"
/>?
</completeCondition>?
<onComplete expression=
"xpath"
[sequence=
"sequence-ref"
]>
(mediator +)?
</onComplete>
</aggregate>
So I have created three APIs. Two for the calling endpoints and the third one for aggregate both responses.
API One.
<?xml version="1.0" encoding="UTF-8"?> <api context="/getResponse1" name="ResponseOneAPI" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="GET"> <inSequence> <payloadFactory media-type="json"> <format> { "name" :"Harshana", "address": "Warakapola", "vehicleNo" : "BGP 3417" } </format> <args/> </payloadFactory> <respond/> </inSequence> <outSequence/> <faultSequence/> </resource> </api>
API Two.
<?xml version="1.0" encoding="UTF-8"?> <api context="/getReponse2" name="RespnoseTwoApi" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="GET"> <inSequence> <payloadFactory media-type="json"> <format> { "name" : "madusanka", "address": "colombo", "vehicleNo" : "BEG 8765" } </format> <args/> </payloadFactory> <respond/> </inSequence> <outSequence/> <faultSequence/> </resource> </api>
Now here is the sample API for aggregate both responses.
<?xml version="1.0" encoding="UTF-8"?> <api context="/aggregrateApi" name="AggregrateSampleAPI" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="GET"> <inSequence> <clone> <target> <sequence> <call> <endpoint> <http method="get" uri-template="http://192.168.56.1:8280/getResponse1"/> </endpoint> </call> <log> <property expression="json-eval($.)" name="log"/> </log> </sequence> </target> <target> <sequence> <call> <endpoint> <http method="get" uri-template="http://192.168.56.1:8280/getReponse2"/> </endpoint> </call> <log> <property expression="json-eval($.)" name="log"/> </log> </sequence> </target> </clone> <payloadFactory media-type="json"> <format> { "response" : { "name" : "$1", "hAddress" : "$2", "vehicle" : "$3" } } </format> <args> <arg evaluator="json" expression="$.name"/> <arg evaluator="json" expression="$.address"/> <arg evaluator="json" expression="$.vehicleNo"/> </args> </payloadFactory> <loopback/> </inSequence> <outSequence> <property name="response" scope="default"> <Responses xmlns=""/> </property> <aggregate> <completeCondition> <messageCount max="-1" min="-1"/> </completeCondition> <onComplete expression="$body//response" enclosingElementProperty="response"> <payloadFactory media-type="json"> <format> { "response1" : $1, "response2" : $2 } </format> <args> <arg evaluator="json" expression="$.Responses.response[0]"/> <arg evaluator="json" expression="$.Responses.response[1]"/> </args> </payloadFactory> <send/> </onComplete> </aggregate> </outSequence> <faultSequence/> </resource> </api>
The Best Casinos & Slot Games in Reno, NV
ReplyDeleteThe Casinos & Slot 강릉 출장안마 Games in Reno, NV · Golden Nugget Hotel · Red 영주 출장마사지 Sands 화성 출장마사지 Hotel & Casino · Planet Hollywood Casino & Spa · SkyCity Hotel 목포 출장안마 & Casino · Planet Hollywood Casino 고양 출장마사지 &