0

I have following JSON data:

{
   "CustomerNames":{
      "Update":[
         {
            "CustName":"Name1",
            "id":"3"
         },
         {
            "CustName":"Name3",
            "id":"32"
         }
      ],
      "Create":[
         {
            "Name":"Name2"
         }
      ]
   }
}

If the Update JSONARray exists I need to call UpdateCustomer Sequence. And if the Create JSONArray exists I need to call CreateCustomer Sequence. I am trying to achieve this using Conditional Router Mediator. I have tried the below code for conditional routing:

<property expression="json-eval($.CustomerNames.Update)" name="CREATE_PAYLOAD" scope="default" type="STRING"/>
<property expression="json-eval($.CustomerNames.Create)" name="UPDATE_PAYLOAD" scope="default" type="STRING"/>

<conditionalRouter continueAfter="true">
                <conditionalRoute asynchronous="true" breakRoute="false">
                    <condition>
                        <match regex="true" source="boolean(get-property('CREATE_PAYLOAD'))"/>
                    </condition>
                    <target sequence="CREATE_CUSTOMER"/>
                </conditionalRoute>
                <conditionalRoute asynchronous="true" breakRoute="false">
                    <condition>
                        <match regex="true" source="boolean(get-property('UPDATE_PAYLOAD'))"/>
                    </condition>
                    <target sequence="UPDATE_CUSTOMER"/>
                </conditionalRoute>
            </conditionalRouter>

But this is not giving desired output. Am I doing anything wrong here?

Ruby
  • 368
  • 1
  • 9

1 Answers1

1

The Conditional Router Mediator was removed from EI 6.5.0 onwards and the latest version doesn't support it. Therefore you may need to use the Switch Mediator to call the required sequences. In the Switch Mediator, if a matching case is found, it will be executed, and the remaining switch cases are not processed. Since you need to call both sequences, you can use two switch mediators as follows,

<property expression="json-eval($.CustomerNames.Update)" name="CREATE_PAYLOAD" scope="default" type="STRING"/>
<property expression="json-eval($.CustomerNames.Create)" name="UPDATE_PAYLOAD" scope="default" type="STRING"/>
<switch source="boolean(get-property('CREATE_PAYLOAD'))">
    <case regex="true">
        <sequence key="CREATE_CUSTOMER"/>
    </case>
    <default/>
</switch>
<switch source="boolean(get-property('UPDATE_PAYLOAD'))">
    <case regex="true">
        <sequence key="UPDATE_CUSTOMER"/>
    </case>
    <default/>
</switch>

For more information check https://ei.docs.wso2.com/en/latest/micro-integrator/references/mediators/switch-Mediator/

sanoJ
  • 2,935
  • 2
  • 8
  • 18
  • I tried this approach of using 2 filter mediators and 2 switch mediators, but I have observed that increases the response time. Is there any way we can achieve it using a single mediator? – Ruby Jan 31 '23 at 07:43
  • What do you have in the sequences? Do you make calls to some backends? – sanoJ Jan 31 '23 at 08:27
  • Yes, we have api calls to backend in both the sequences – Ruby Jan 31 '23 at 08:39