Routerule in ServiceCallout

Is it possible to use RouteRule in ServiceCallOut Policy?

My requirement : In ServiceCallOut Policy, HTTPTargetConnection/URL will changes dynamically based on environment.name. Please suggest best approach.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-1">
    <DisplayName>Service Callout-1</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    </Request>
    <Response>calloutResponse</Response>
    <RouteRule>
        <Condition>(environment.name = "test")</Condition>
        <HTTPTargetConnection>
            <URL>http://test.apis.com</URL>
        </HTTPTargetConnection>
    </RouteRule>
    <RouteRule>
        <Condition>(environment.name = "uat")</Condition>
        <HTTPTargetConnection>
            <URL>http://uat.apis.com</URL>
        </HTTPTargetConnection>
    </RouteRule>
    <RouteRule>
        <Condition>(environment.name = "prod")</Condition>
        <HTTPTargetConnection>
            <URL>http://prod.apis.com</URL>
        </HTTPTargetConnection>
    </RouteRule>
</ServiceCallout>

0 1 180
1 REPLY 1

@Santhosh Malluru

There is no provision to use routerules in a service callout.

Looking at your example above, it seems like you should use a target server configuration in the service callout and let it handle the environment based backends. You can see more information in the post below.

https://community.apigee.com/questions/37721/how-do-we-configure-and-call-target-server-from-se.html

If you need some conditional routing to be done to multiple backends by using service callouts, an alternative would be to execute your service callout conditionally

<Step>
                    <FaultRules/>
                    <Name>ServiceCallout-1</Name>
<Condition>request.header.abc = "route1"</Condition>
                </Step>

<Step>
                    <FaultRules/>
                    <Name>ServiceCallout-2</Name>
<Condition>request.header.abc = "route2"</Condition>
                </Step>