Статьи

WSO2 ESB Клонирование и агрегация с использованием образца поезда

В Европе есть много мест для посещения, и поезда будут лучшим способом передвигаться, а не летать, если вы хотите насладиться окрестностями. Но при поиске поезда из одного города страны в другой город округа Европы результаты не так уж сильны для ожиданий гостей. Много времени это дает результат как

«Извините, но мы не смогли найти никаких результатов для вашего поиска» красными буквами.

Но хорошо для мастеров города. Но здесь я не собираюсь говорить о поездах или Европе.

Позвольте перейти к техническому (IT) миру или перспективе SOA. Каждый поставщик услуг поезда будет иметь интерфейс, где он будет предоставлять свои услуги. Например, когда пользователь запрашивает пункт назначения с определенной начальной точкой, он / она будет получать поезда по этому пути с ценой и продолжительностью в часах. (Плюс оставляя время от места старта)

образ

Здесь у меня есть сервис для демонстрации с wso2 Data Services с MySQL. Вот услуги от Thalys.

Вот данные Сервисы для ТВГ

<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>

Теперь создайте то же самое для других

Вот пример веб-запроса

<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>

Образец ответа

<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>

Затем ESB для прокси-сервера для клонирования и агрегирования (если ответ и другое, то используйте посредник XSLT для информирования тех, кто входит в одну формацию)

<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>

Тогда попробуйте прокси отсюда вы увидите все ответы в одном сообщении


образ

Время наслаждаться присоединением к большему количеству услуг с Clone и Aggregate.