How to set dynamic LoadBalancer for HTTPTargetConnection Target Server in APIGEE?

I want to have a different server for my APIGEE load balancer Based on an if/else condition.

This is my current config that works a single server name (non dynamic):

<HTTPTargetConnection>
    <Properties>
        <Property name="response.streaming.enabled">true</Property>
    </Properties>
    <LoadBalancer>
        <Server name="test1"/>
    </LoadBalancer>
    <Path>{pathSuffix}</Path>
</HTTPTargetConnection>

I'm trying to make the <Server name="test1"/> dynamically change based on an if condition:

Something Like:

<HTTPTargetConnection>
    <Properties>
        <Property name="response.streaming.enabled">true</Property>
    </Properties>
    <LoadBalancer>
        <Condition>reroute = "FALSE"</Condition>
        <Server name="test1"/>
    </LoadBalancer>
    <LoadBalancer>
        <Condition>reroute = "TRUE"</Condition>
        <Server name="test2"/>
    </LoadBalancer>
    <Path>{pathSuffix}</Path>
</HTTPTargetConnection>

But it is not working. How can I have dynamically change the Server name here? or is there any other recommended way to do this?

0 1 567
1 REPLY 1

hello, 

I think you should define 2 target endpoint.

The target endpoint is selected in the Proxy Endpoint execution: there is a RouteRule tag to select the endpoint.

<RouteRule name="MyRoute">
  <Condition>request.header.routeTo = "TargetEndpoint1"</Condition>
  <TargetEndpoint>TargetEndpoint1</TargetEndpoint>
</RouteRule>
<RouteRule name="default">
  <TargetEndpoint>TargetEndpoint2</TargetEndpoint>
</RouteRule>

Reference:

https://cloud.google.com/apigee/docs/api-platform/fundamentals/understanding-routes#determiningtheur...

https://www.googlecloudcommunity.com/gc/Apigee/Multiple-Target-Endpoints-Group/td-p/61520