[HTTPTargetConnection]How to set the same target server but different path in <LoadBalancer>

Hello,

I've been doing some experiments to see if there's a way to use the built-in policy to accomplish some tasks without writing javascript.

The purpose of this experiment is because some customers have asked: the same API calls to the same host, but only the back-end resource path is different, such as
https://same_hostname/path1
https://same_hostname/path2

Here is my question:

If I set only one host in Target Servers, is it possible to implement the same server but different paths in <LoadBalancer> setting in <HTTPTargetConnection>? And can I also apply <Algorithm>Weighted</Algorithm>?

 

<HTTPTargetConnection>
  <LoadBalancer>
    <Algorithm>Weighted</Algorithm>
    <Server name="mock">
      <Weight>1</Weight>
    </Server>
    <Path>/ip</Path>
    <Server name="mock">
      <Weight>2</Weight>
    </Server>
    <Path>/xml</Path>
  </LoadBalancer>
</HTTPTargetConnection>

 

The above example is absolutely wrong, is there any other suggested way to achieve the customer's purpose?

Reference - Load balancing across backend servers 

Thanks!

0 3 201
3 REPLIES 3

What's the use case for different paths at random? 

The load balancer is intended to help load balance/distribute traffic across a pool of servers.. 

If you have non-random use case, ie conditional to something, you could introduce another target endpoint with the same server/s, but different path. The route to that target could then be conditional

https://docs.apigee.com/api-platform/fundamentals/understanding-routes#determiningtheurlofthetargete...

Hi @dknezic Thanks for your reply!

The customer actually wants to achieve:
1. Their Target Server hostname is the same, but the path attached to it is different.
2. Under the above premise, how can Apigee direct the traffic? Because they have mentioned that under the same API call, can it be possible to direct 10% of the traffic to server A and 90% to server B?

If I use the way you provided, I read the documentation:

截圖 2023-01-11 下午5.27.25.png

How can I achieve the scenario where 10% of the traffic is directed to A server and 90% to B server?

it seems like routing and load balancing concepts are mixed here.

what's the relationship/mapping between Server A and Server B and /ip and /xml endpoints? ie, which server implements which endpoint?