user2749166
user2749166

Reputation: 49

WSO2 ESB Aggregate Mediator sending more messages out than the the number that was sent out

I have built an API that sends messages to multiple endpoints using clone mediator. I have also used an aggregate mediator to collect the messages that are returned by the endpoints to one message and send it back to the client. Below is the outsequence that has the aggregate mediator:

        <outSequence>
        <aggregate id="GetOpenTasksReq">
            <completeCondition>
                <messageCount max="-1" min="-1"/>
            </completeCondition>
            <onComplete expression="//jsonObject" xmlns:m0="http://ws.wso2.org/dataservice">
                <log level="custom" separator=",">
                    <property name="MessageFlow" value="======================= Sending Back the Aggregated Responses. ==============="/>
                </log>
                <log level="full" separator=","/>
                <enrich>
                    <source clone="true" xpath="//tasks"/>
                    <target action="child" type="body"/>
                </enrich>
                <property name="messageType" value="application/json" scope="axis2"/>
                <send/> 
            </onComplete>
        </aggregate>
        <send/> 
    </outSequence>

It was supposed to return

    {
  "tasks": [
    {
      "id": 10,
      "desc": "New Assignment Item",
      "due": "2019-02-18T06:23:41+07:00",
      "link": "https://[host]:[port]/viewtask?id=10"
    },
    {
      "id": 1,
      "desc": "New Assignment Item",
      "due": "2019-02-18T06:23:41+07:00",
      "link": "https://[host]:[port]/viewtask?id=1"
    },
    {
      "id": 33,
      "desc": "New Assignment Item",
      "due": "2019-02-18T06:23:41+07:00",
      "link": "https://[host]:[port]/viewtask?id=33"
    }
  ]
}

But instead I got :

    {
  "tasks": [
    {
      "id": 10,
      "desc": "New Assignment Item",
      "due": "2019-02-18T06:23:41+07:00",
      "link": "https://[host]:[port]/viewtask?id=10"
    },
    {
      "id": 10,
      "desc": "New Assignment Item",
      "due": "2019-02-18T06:23:41+07:00",
      "link": "https://[host]:[port]/viewtask?id=10"
    },
    {
      "id": 1,
      "desc": "New Assignment Item",
      "due": "2019-02-18T06:23:41+07:00",
      "link": "https://[host]:[port]/viewtask?id=1"
    },
    {
      "id": 33,
      "desc": "New Assignment Item",
      "due": "2019-02-18T06:23:41+07:00",
      "link": "https://[host]:[port]/viewtask?id=33"
    }
  ]
}

For some reasons one of the response from one of the endpoints gets repeated. I have tried retriggering the request to the API on the ESB but it would always repeat one of the reponses. Can you kindly help me by looking at my aggregate mediator configuration and see if there is any error? As usual thanks in advance.

Upvotes: 1

Views: 342

Answers (1)

Reza Ameri
Reza Ameri

Reputation: 1815

Seems your Enrich mediator is making the problem. To make it clear I try to explain an example, it is not exactly how Aggregator works but it may clear the reason for the problem. By receiving the first response it Enriches the //tasks to the body. By receiving the second response, again it does the same, as you may guess, body is already has something in it under the //tasks so in the second time it aggregates two //tasks.

It is better to use another property instead of enriching the body.

Upvotes: 0

Related Questions