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! Go to 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:
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
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
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:
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
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
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