2017-01-26 6 views
0

WSO2 ESBを使用して、2つの異なるデータソースを1つのデータフィードに結合しようとしています。さまざまなソースが異なるデータ形式を持っているため、私は、エンドポイントごとに承認とペイロードのフォーマットを処理するプロキシを作成して、両方がJSON配列を返すようにしました。研究に基づいて、私は、アグリゲータメディアを使用して結果を結合することができたと仮定しました。たくさんの例を試した結果、2つの配列をうまく組み合わせましたが、配列の1つは常に重複しています。私が間違っていることを誰かが見ることができますか、誰かが2つのJSON配列の組み合わせを実現する良い方法について他の提案をしていますか?WSO2アグリゲーターを使用して複数のJSON配列を結合する

<?xml version="1.0" encoding="UTF-8"?> 
<proxy name="testb_url1" startOnLoad="true" trace="disable" 
    transports="https http" xmlns="http://ws.apache.org/ns/synapse"> 
    <target> 
    <inSequence> 
      <payloadFactory media-type="json"> 
     <format>[ 
      {"id": "1", 
      "type": "object", 
      "name": "first"}, 
      {"id": "2", 
      "type": "object", 
      "name": "second"} 
      ] 
      </format> 
     <args/> 
     </payloadFactory> 
     <log level="full"/> 
     <loopback/> 
    </inSequence> 
    <outSequence> 
     <send/> 
    </outSequence> 
    <faultSequence/> 
    </target> 
</proxy> 

URL数2

<?xml version="1.0" encoding="UTF-8"?> 
<proxy name="testb_url2" startOnLoad="true" trace="disable" 
    transports="https http" xmlns="http://ws.apache.org/ns/synapse"> 
    <target> 
    <inSequence> 
      <payloadFactory media-type="json"> 
     <format>[ 
      {"id": "10", 
      "type": "object", 
      "name": "ten"}, 
      {"id": "11", 
      "type": "object", 
      "name": "eleven"} 
      ] 
      </format> 
     <args/> 
     </payloadFactory> 
     <log level="full"/> 
     <loopback/> 
    </inSequence> 
    <outSequence> 
     <send/> 
    </outSequence> 
    <faultSequence/> 
    </target> 
</proxy> 

コード組み合わせること:

<?xml version="1.0" encoding="UTF-8"?> 
<proxy name="testb_combine" startOnLoad="true" trace="disable" 
    transports="https http" xmlns="http://ws.apache.org/ns/synapse"> 
    <target> 
    <inSequence> 
     <property name="enclosing_element" scope="default"> 
      <jsonArray xmlns=""/> 
     </property> 
     <send> 
      <endpoint> 
       <recipientlist> 
        <endpoint> 
        <address uri="http://localhost:8280/services/testb_url1/" trace="disable"/> 
        </endpoint> 
        <endpoint> 
        <address uri="http://localhost:8280/services/testb_url2/" trace="disable"/> 
        </endpoint> 
       </recipientlist> 
      </endpoint> 
     </send>  
    </inSequence> 
    <outSequence> 
     <enrich> 
      <source clone="true" xpath="$body/jsonArray/jsonElement"/> 
      <target action="child" xpath="$ctx:enclosing_element"/> 
     </enrich> 
     <aggregate> 
      <completeCondition> 
       <messageCount min="-1" max="-1"/> 
      </completeCondition> 
      <onComplete expression="$body/jsonArray/jsonElement" 
         enclosingElementProperty="enclosing_element"> 
       <send/> 
      </onComplete> 
     </aggregate> 
     </outSequence> 
    <faultSequence/> 
    </target> 
</proxy> 
私は2つのフィードをシミュレートして、私のコードと結合するために、次のコード例を設定している

URL 1のデータが重複して返されて返された結果:

[ 
    { 
    "id": 1, 
    "type": "object", 
    "name": "first" 
    }, 
    { 
    "id": 2, 
    "type": "object", 
    "name": "second" 
    }, 
    { 
    "id": 1, 
    "type": "object", 
    "name": "first" 
    }, 
    { 
    "id": 2, 
    "type": "object", 
    "name": "second" 
    }, 
    { 
    "id": 10, 
    "type": "object", 
    "name": "ten" 
    }, 
    { 
    "id": 11, 
    "type": "object", 
    "name": "eleven" 
    } 
] 

答えて

3

outsequenceでエンリッチ仲介者を削除し、あなたが望むようにそれは動作: プロキシサービス:

<?xml version="1.0" encoding="UTF-8"?> 
<proxy xmlns="http://ws.apache.org/ns/synapse" 
     name="testb_combine" 
     transports="https http" 
     startOnLoad="true"> 
    <target> 
     <inSequence> 
     <property name="enclosing_element" scope="default"> 
      <jsonArray xmlns=""/> 
     </property> 
     <send> 
      <endpoint> 
       <recipientlist> 
        <endpoint> 
        <address uri="http://localhost:8283/services/testb_url1/"/> 
        </endpoint> 
        <endpoint> 
        <address uri="http://localhost:8283/services/testb_url2/"/> 
        </endpoint> 
       </recipientlist> 
      </endpoint> 
     </send> 
     </inSequence> 
     <outSequence> 
     <aggregate> 
      <completeCondition> 
       <messageCount min="-1" max="-1"/> 
      </completeCondition> 
      <onComplete expression="$body/jsonArray/jsonElement" 
         enclosingElementProperty="enclosing_element"> 
       <send/> 
      </onComplete> 
     </aggregate> 
     </outSequence> 
     <faultSequence/> 
    </target> 
</proxy> 

は応答:

[ 
    { 
     "id": 1, 
     "type": "object", 
     "name": "first" 
    }, 
    { 
     "id": 2, 
     "type": "object", 
     "name": "second" 
    }, 
    { 
     "id": 10, 
     "type": "object", 
     "name": "ten" 
    }, 
    { 
     "id": 11, 
     "type": "object", 
     "name": "eleven" 
    } 
] 
関連する問題