WSO2 ESB Cloning and Aggregating With Train Sample
Join the DZone community and get the full member experience.
Join For FreeIn Europe there are some many places to visit and trains will be best way to move rather than flying if you wish to enjoy surroundings. But when you search for train from one country city to another Europe county city results are not much powerful for guest expectations. Lot of time it give result as
" Sorry, but we couldn’t find any results for your search" in red letters.
But fine for master cities. But in here I am not going talk about Trains or Europe.
Let go to technical (IT) world or SOA perspective. Each Train Services provider will have and interface where they expose their services . Such as when user request destination with particular start point he/she will get trains on that path with price and duration in hours. (Plus Leaving time from starting location)
Here I have service for demo with wso2 Data services with MySQL. Here is services from Thalys.
Here is data Services for TVG
<data name="TGV"> <config id="mysql1"> <property name="driverClassName">com.mysql.jdbc.Driver</property> <property name="url">jdbc:mysql://localhost:3306/trains</property> <property name="username">root</property> <property name="password">root</property> </config> <query id="getTVGTrains" useConfig="mysql1"> <sql>SELECT StartingLocation, EndingLocation, TourDuration, TicketPrice, TrainsName, LeavingTime FROM `trains` WHERE `TrainsName` LIKE '%TVG%' AND StartingLocation = :StartingLocation AND EndingLocation = :EndingLocation</sql> <result element="Entries" rowName="Entry"> <element column="StartingLocation" name="StartingLocation" xsdType="string"/> <element column="EndingLocation" name="EndingLocation" xsdType="string"/> <element column="TourDuration" name="TourDuration" xsdType="string"/> <element column="TicketPrice" name="TicketPrice" xsdType="string"/> <element column="TrainsName" name="TrainsName" xsdType="string"/> <element column="LeavingTime" name="LeavingTime" xsdType="string"/> </result> <param name="StartingLocation" sqlType="STRING"/> <param name="EndingLocation" sqlType="STRING"/> </query> <operation name="getTrains"> <call-query href="getTVGTrains"> <with-param name="StartingLocation" query-param="StartingLocation"/> <with-param name="EndingLocation" query-param="EndingLocation"/> </call-query> </operation> </data>
Now create same to other also
Here is sample Web request
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice"> <soapenv:Header/> <soapenv:Body> <dat:getTrains> <dat:StartingLocation>Turin</dat:StartingLocation> <dat:EndingLocation>Paris</dat:EndingLocation> </dat:getTrains> </soapenv:Body> </soapenv:Envelope>
Sample respond
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <Entries xmlns="http://ws.wso2.org/dataservice"> <Entry> <StartingLocation>Turin</StartingLocation> <EndingLocation>Paris</EndingLocation> <TourDuration>5:30 hours</TourDuration> <TicketPrice>150</TicketPrice> <TrainsName>TVG-2302</TrainsName> <LeavingTime>8.30AM</LeavingTime> </Entry> <Entry> <StartingLocation>Turin</StartingLocation> <EndingLocation>Paris</EndingLocation> <TourDuration>4:30 hours</TourDuration> <TicketPrice>150</TicketPrice> <TrainsName>TVG-3444</TrainsName> <LeavingTime>10.00AM</LeavingTime> </Entry> </Entries> </soapenv:Body> </soapenv:Envelope>
Then ESB for Proxy For Cloning and aggregating (If respond and different then use XSLT mediator for informing those in to one formation)
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AllEuropTrains" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <clone> <target> <endpoint name="TGV"> <address uri="http://localhost:9764/services/TGV/"/> </endpoint> </target> <target> <endpoint name="EUROStar"> <address uri="http://localhost:9764/services/EUROStar/"/> </endpoint> </target> <target> <endpoint name="THYLYS"> <address uri="http://localhost:9764/services/THYLYS/"/> </endpoint> </target> </clone> </inSequence> <outSequence> <aggregate> <completeCondition> <messageCount min="-1" max="-1"/> </completeCondition> <onComplete xmlns:m0="http://ws.wso2.org/dataservice" expression="//m0:Entries"> <log level="custom" separator=","> <property name="MessageFlow" value="======================= Sending Back the Aggregated Responses. ==============="/> </log> <log level="full" separator=","/> <enrich> <source xmlns:m1="http://ws.wso2.org/dataservice" clone="true" xpath="//m1:Entries/m1:Entry"/> <target type="body" action="child"/> </enrich> <send/> </onComplete> </aggregate> </outSequence> </target> <publishWSDL key="conf:/blog/train/AllTrain.wsdl"/> <description></description> </proxy>
Then Try out the proxy from here you will see all respond in one message
Time to enjoy joying more services with Clone and Aggregate.
Published at DZone with permission of Eric Genesky. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
-
A React Frontend With Go/Gin/Gorm Backend in One Project
-
What Is Envoy Proxy?
-
Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices
Comments