Target Endpoint/Server callout

Not applicable

I need to make a callout to Target Endpoint or Target Server in one of my flows and apply load balancing rules. Is there a way to do this using javascript or any other policy?

Solved Solved
2 10 4,818
1 ACCEPTED SOLUTION

Hi @MSaichuk

Welcome to Apigee Community !!!

Please refer to the Service Callout policy for example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="service-callout">
    <DisplayName>service-callout</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    </Request>
    <Response>myResponse</Response>
    <HTTPTargetConnection>
        <LoadBalancer>
            <Algorithm>RoundRobin</Algorithm>
            <Server name="httpbin"/>
            <Server name="yahoo"/>
        </LoadBalancer>
        <Path>/get</Path>
    </HTTPTargetConnection>
</ServiceCallout>

If you don't want to use Service Callout as mentioned above, you can achieve the same thing by defining a separate TargetEndpoint for that flow. Within the proxy endpoint, you can create a Route Rule to call that TargetEndpoint

<!-- Route rule for other target -->
<RouteRule name="second-target-endpoint">
    <Condition>(proxy.pathsuffix MatchesPath "/other")</Condition> <!-- /other is just an example here -->
    <TargetEndpoint>second-target-endpoint</TargetEndpoint>
</RouteRule>

<!-- Default -->
<RouteRule name="default">
    <TargetEndpoint>default</TargetEndpoint>
</RouteRule>

NOTE: Make sure the default route rule is placed at the end in the proxy end point

2835-screen-shot-2016-06-01-at-94435-am.png

And inside the second-target-endpoint configuration, you can use the Target Servers configured with load balancer

<HTTPTargetConnection>
        <LoadBalancer>
            <Algorithm>RoundRobin</Algorithm>
            <Server name="Target1"/>
            <Server name="Target2"/>
        </LoadBalancer>
    </HTTPTargetConnection>

Hope this helps ! Please reach out if you still have any questions.

View solution in original post

10 REPLIES 10

Hi @MSaichuk

Welcome to Apigee Community !!!

Please refer to the Service Callout policy for example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="service-callout">
    <DisplayName>service-callout</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    </Request>
    <Response>myResponse</Response>
    <HTTPTargetConnection>
        <LoadBalancer>
            <Algorithm>RoundRobin</Algorithm>
            <Server name="httpbin"/>
            <Server name="yahoo"/>
        </LoadBalancer>
        <Path>/get</Path>
    </HTTPTargetConnection>
</ServiceCallout>

If you don't want to use Service Callout as mentioned above, you can achieve the same thing by defining a separate TargetEndpoint for that flow. Within the proxy endpoint, you can create a Route Rule to call that TargetEndpoint

<!-- Route rule for other target -->
<RouteRule name="second-target-endpoint">
    <Condition>(proxy.pathsuffix MatchesPath "/other")</Condition> <!-- /other is just an example here -->
    <TargetEndpoint>second-target-endpoint</TargetEndpoint>
</RouteRule>

<!-- Default -->
<RouteRule name="default">
    <TargetEndpoint>default</TargetEndpoint>
</RouteRule>

NOTE: Make sure the default route rule is placed at the end in the proxy end point

2835-screen-shot-2016-06-01-at-94435-am.png

And inside the second-target-endpoint configuration, you can use the Target Servers configured with load balancer

<HTTPTargetConnection>
        <LoadBalancer>
            <Algorithm>RoundRobin</Algorithm>
            <Server name="Target1"/>
            <Server name="Target2"/>
        </LoadBalancer>
    </HTTPTargetConnection>

Hope this helps ! Please reach out if you still have any questions.

Hello @Sai Saran Vaidyanathan.

Thanks for your answer! I think I've messed up with the question a little bit so I would like to clarify if I can make callout(reuse) to already configured Target Endpoint so if I need to add few servers - I can add them in one common place. Also I need to process Target Endpoint response data as part of my flows, so I think I can't achieve it by using RouteRules only. Using screenshot you provided, I need process response data from target endpoint "second-target-endpoint" callout as part of Proxy Endpoint default PostFlow.

The option that came to my mind I can try to create Proxy Endpoint within the same API Proxy that passes requests directly to the Target Endpoint and then make a callout to it using LocalTargetConnection.

@MSaichuk , You can create a different API proxy with a target endpoint which includes multiple target servers for load balancing. You can call this API Proxy (Reusable Proxy) using Proxy Chaining concept using LocalTargetConnection from any other API Proxy. Hope it helps.

@MSaichuk , Welcome to Apigee Community,

Just need small clarification, would you like to do load balancing on target endpoints (backend servers) so that you can route traffic to different target servers ? If yes, Please see @Sai Saran Vaidyanathan answer. Find more about same here.

Would you like to do load balancing of service callouts policy initiated target endpoints ? I am not sure about that. It (Service Callout policy) uses same XML element ("HTTPTargetConnection") to configure endpoint. @Sai Saran Vaidyanathan , It will be interesting to find out.

@Anil Sagar - Looks like you can call target servers within Service Callout policy. I tested it using a simple proxy. Have updated the answer below to include both solutions.

We should update the policy docs in that case - @Floyd Jones, @wwitman

Awesome, Thank you for confirming @Sai Saran Vaidyanathan

Short term, I added <LoadBalancer> in the element reference of Service Callout to at least show it as an option. This is a great use case to document better, and @wwitman is going to put something together. Thanks, @Sai Saran Vaidyanathan!

Awesome.. Thanks @Floyd Jones

Awesome, Thank you @Floyd Jones for the update.