WSO2 ESB, How to combine 2 messages using aggregate mediator or any other mediator

546 views Asked by At

I'm new to WSO2 Enterprise Integrator.
I'm having hardtime combining this two messages using aggrerate mediator.
I have put my 1st message in property so I can access individual values (Is there any other way doing it?)
Required output is in json format. (I have tried for each but it's only looping in message 2 loop messages.)

Input message 1:

{
  "customerId": "ABC123",
  "channelNo": "1",
  "codename": "code123"
}

Input Message 2:

{
  "lnsAcctInfo": [
    {
      "acctno": "101991100000012",
      "custid": "2018111400000002",
      "acctype": null,
      "ccy": null,
      "name": null,
      "prdcode": "300"
    },
    {
      "acctno": "101991100000022",
      "custid": "2018111400000052",
      "acctype": 1,
      "ccy": 1,
      "name": 1,
      "prdcode": "300"
    }
  ]
}

Output required:

{
  "customerId": "ABC123",
  "codename": "code123",
  "lnsAcctInfo": [
    {
      "acctno": "101991100000012",
      "custid": "2018111400000002",
      "acctype": null
    },
    {
      "acctno": "101991100000022",
      "custid": "2018111400000052",
      "acctype": 1
    }
  ]
}

Here's the synapse code:

<resource methods="POST" uri-template="/foreach">
  <inSequence>
    <log>
      <property expression="json-eval($)" name="RecievedPostMessage" />
    </log>
    <property name="customid" scope="default" type="STRING" value="sampleuserid" />
    <payloadFactory description="payload-xml" media-type="xml">
      <format>
        <lnsAcctInfo xmlns="">$1</lnsAcctInfo>
      </format>
      <args>
        <arg evaluator="json" expression="$.lnsAcctInfo[*]" />
      </args>
    </payloadFactory>
    <log>
      <property expression="." name="payload1" />
    </log>
    <iterate expression="//lnsAcctInfo/jsonElement" id="1">
      <target>
        <sequence>
          <log>
            <property expression="." name="Iterate" />
          </log>
          <aggregate>
            <completeCondition>
              <messageCount max="-1" min="-1" />
            </completeCondition>
            <onComplete expression="//jsonElement">
              <log>
                <property expression="." name="aggre" />
              </log>
            </onComplete>
          </aggregate>
        </sequence>
      </target>
    </iterate>
    <log>
      <property expression="." name="overall" />
    </log>
    <respond />
  </inSequence>
  <outSequence>
    <send />
  </outSequence>
  <faultSequence />
</resource>
0

There are 0 answers