Target Endpoint with multiple flows

Not applicable

I have a requirement in which i need to route the request to target endpoint based on region which i am able to do that in proxy endpoint using routing rule, but the thing is i need one target endpoint with many flow inside that based on request instead of multiple end point, Each request flow have same target server name but they differ in <path> I am using load balancer , how could i achieve it.

Solved Solved
1 4 998
1 ACCEPTED SOLUTION

Dear @Umanng,

Here is one of the ways you can have a single target endpoint with many flows and then set different paths for each flow:

1. Create a target server (let's say CommonTarget and set some common target host name in it along with the port number).

2. Define the HTTPTargetConnection with a variable let's say "targetPath" as shown below in your Target Endpoint:

<HTTPTargetConnection>
    <LoadBalancer>
        <Server name="CommonTarget"/>
    </LoadBalancer>
    <Path>{targetPath}</Path>
</HTTPTargetConnection>

3. Then you can the do the following:

  • Have separate Javascript policy/code for each flow in the Target Endpoint and set an appropriate value for the variable targetPath. Below are some examples
  • Ex:
Javascript_User
var targetPath="";
var userId = context.getVariable("userId");
targetPath=targetPath+"v1/user/"+userId;
context.setVariable("targetPath",targetPath);

Ex: Javascript_Service

var targetPath="";
var serviceName = context.getVariable("serviceName");
targetPath=targetPath+"v1/service/"+serviceName;
context.setVariable("targetPath",targetPath);

OR

  • Have one common Javascript policy/code in the target request flow, where you can set the variable targetPath to an appropriate value depending on certain condition/input parameters
var targetPath="";
var userId = context.getVariable("userId");
var serviceName = context.getVariable("serviceName");
if (userId !== undefined ||  userId !== null) {
   targetPath=targetPath+"v1/user/"+userId;
}
if (serviceName !== undefined || serviceName !== null){
   targetPath=targetPath+"v1/service/"+serviceName;
}
context.setVariable("targetPath",targetPath);

Note: This is sample code snippet, you can write the code appropriately based on your requirements.

Regards,

Amar

View solution in original post

4 REPLIES 4

Dear @Umanng,

Here is one of the ways you can have a single target endpoint with many flows and then set different paths for each flow:

1. Create a target server (let's say CommonTarget and set some common target host name in it along with the port number).

2. Define the HTTPTargetConnection with a variable let's say "targetPath" as shown below in your Target Endpoint:

<HTTPTargetConnection>
    <LoadBalancer>
        <Server name="CommonTarget"/>
    </LoadBalancer>
    <Path>{targetPath}</Path>
</HTTPTargetConnection>

3. Then you can the do the following:

  • Have separate Javascript policy/code for each flow in the Target Endpoint and set an appropriate value for the variable targetPath. Below are some examples
  • Ex:
Javascript_User
var targetPath="";
var userId = context.getVariable("userId");
targetPath=targetPath+"v1/user/"+userId;
context.setVariable("targetPath",targetPath);

Ex: Javascript_Service

var targetPath="";
var serviceName = context.getVariable("serviceName");
targetPath=targetPath+"v1/service/"+serviceName;
context.setVariable("targetPath",targetPath);

OR

  • Have one common Javascript policy/code in the target request flow, where you can set the variable targetPath to an appropriate value depending on certain condition/input parameters
var targetPath="";
var userId = context.getVariable("userId");
var serviceName = context.getVariable("serviceName");
if (userId !== undefined ||  userId !== null) {
   targetPath=targetPath+"v1/user/"+userId;
}
if (serviceName !== undefined || serviceName !== null){
   targetPath=targetPath+"v1/service/"+serviceName;
}
context.setVariable("targetPath",targetPath);

Note: This is sample code snippet, you can write the code appropriately based on your requirements.

Regards,

Amar

@AMAR DEVEGOWDA

Thanks for the info, It works 🙂

I tried with assign message too using set Path variable but it didn't work.

Regards,

Umanng

Dear @Umanng,

There's an issue with Set Path in Assign Message Policy. You can find more information on this in this community post, so it wouldn't work.

Thanks,

Amar

Thanks for the details @AMAR DEVEGOWDA