Can we define a target server name at runtime

I have a proxy where in am using "Routerules" to route requests to different Target Endpoints. Each Target Endpoint has a target server "name" defined in it. Is there a way to decide this name at runtime?

More specifically my Target Endpoint is configured as

<HTTPTargetConnection> <LoadBalancer> <Server name="IDS"/> </LoadBalancer> <Path>/pathhere</Path> </HTTPTargetConnection>.

Can we parametrize "<Server name="IDS"/>" . Say for example if the hostname in the request is api-ste01.domain.com I want the server name to be "IDS1" if the hostname is api-ste02.domain.com I want the server name to be "IDS2" and so on

Thanks,

Vednath

Solved Solved
0 3 867
1 ACCEPTED SOLUTION

Hi @vednath pittala ,

Using TargetServers will not be helpful in your case. If you don't want to use route rules which will result in a lot of redundant code then perhaps you can define a KVM, say target_endpoints.

The KVM should be configured like, the key will have the name of the server "DS1" or "DS2" and value will be a JSON string as a target server representation.

Please refer this configuration at https://community.apigee.com/answers/34943/view.html

This KVM you can read in your proxy and based on your conditions for target endpoint build and set "target.url" in target flow to route the request to the respective target endpoint.

You can use a Javascript Callout to do this.

Cheers!

View solution in original post

3 REPLIES 3

nmallesh
Participant V

Hi @vednath pittala,

Here is one of the ways you can opt for -

Define Route Rules as below -

<RouteRule name="IDS-1">
        <Condition>Condition for IDS-1...</Condition>
        <TargetEndpoint>IDS1</TargetEndpoint>
</RouteRule>

<RouteRule name="IDS-2">
        <Condition>Condition for IDS-2...</Condition>
        <TargetEndpoint>IDS2</TargetEndpoint>
</RouteRule>

RouteRule for IDS-3 and so on ...

<RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
</RouteRule>

Define all the possible target-end-points as below -

IDS-1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="IDS1">
    <Description>IDS-1</Description>
    <FaultRules/>
    <PreFlow name="PreFlow">
        ...
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <DefaultFaultRule name="fault-rule">
        ...
    </DefaultFaultRule>
    <HTTPTargetConnection>
        <Properties/>
        <LoadBalancer>
            <Server name="ids-1"/>
        </LoadBalancer>
        <Path>/pathhere</Path>
    </HTTPTargetConnection>
</TargetEndpoint>




IDS-2

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="IDS2">
    <Description>IDS-2</Description>
    <FaultRules/>
    <PreFlow name="PreFlow">
        ...
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <DefaultFaultRule name="fault-rule">
        ...
    </DefaultFaultRule>
    <HTTPTargetConnection>
        <Properties/>
        <LoadBalancer>
            <Server name="ids-2"/>
        </LoadBalancer>
        <Path>/pathhere</Path>
    </HTTPTargetConnection>
</TargetEndpoint>




IDS-3 and so on
...


default

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description>default</Description>
    <FaultRules/>
    <PreFlow name="PreFlow">
        ...
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <DefaultFaultRule name="fault-rule">
        ...
    </DefaultFaultRule>
    <HTTPTargetConnection>
        <Properties/>
        <LoadBalancer>
            <Server name="default"/>
        </LoadBalancer>
        <Path>/pathhere</Path>
    </HTTPTargetConnection>
</TargetEndpoint>

Based on the route rule condition, corresponding target end point configuration is picked up and executed in an API proxy.

Keep us posted, thank you!

@Nisha Mallesh I have something like this in my config

<RouteRule name="instruments_ids_cusip_get"> <Condition>(proxy.pathsuffix MatchesPath "/{cusip}") and (request.verb = "GET")</Condition> <TargetEndpoint>IDS</TargetEndpoint> </RouteRule> <RouteRule name="instruments_ids_get"> <Condition>(request.verb = "GET")</Condition> <TargetEndpoint>IDS</TargetEndpoint> </RouteRule>

The condition above needs to be the same as in irrespective of which environment the request comes to it needs to follow this path.

Now when the request reaches the target endpoint based on the hostname in the header I want to decide the Targetserver name. I understand that I could include this condition for host header name in route rule condition itself but doing so would make a lot of lines of code redundant. Like in the example above for 8 different environments i need to write the same code 8 times vs writing it once in target endpoint.

Let me know if there is a way to do this.

Thanks,

Vednath

Hi @vednath pittala ,

Using TargetServers will not be helpful in your case. If you don't want to use route rules which will result in a lot of redundant code then perhaps you can define a KVM, say target_endpoints.

The KVM should be configured like, the key will have the name of the server "DS1" or "DS2" and value will be a JSON string as a target server representation.

Please refer this configuration at https://community.apigee.com/answers/34943/view.html

This KVM you can read in your proxy and based on your conditions for target endpoint build and set "target.url" in target flow to route the request to the respective target endpoint.

You can use a Javascript Callout to do this.

Cheers!