How to create a target server (environment configuration) on a route rule condition

I have a proxy in which the target endpoints default i've created the following load balancer target server which then depedant on the proxy environment eg. Prod, test etc routes to the relevant target specified in the environment configuration. This works perfectly as entered as per below :

<HTTPTargetConnection>
<LoadBalancer>
<Server name="target1"/>
</LoadBalancer>
<Path>/api/v1</Path>
</HTTPTargetConnection>

The question i have is that in the proxy endpoints flows i have two endpoints with a route rule to a different URL as they use a different path completely and their target is set as

<URL>https://example.com/reports</URL>

eg :

<RouteRule name="screening_report">
<Condition>(proxy.pathsuffix MatchesPath "/example1_report**") and (request.verb = "GET")</Condition>
<URL>https://example.com/reports</URL>
</RouteRule>
<RouteRule name="trade_report">
<Condition>(proxy.pathsuffix MatchesPath "/example2_report**") and (request.verb = "GET")</Condition>
<URL>https://example.com/reports</URL>
</RouteRule>

Is there a way to load balance these two endpoints also defining environment using the target server config? eg again being able to specify relevant back end environment?

Solved Solved
0 6 1,344
1 ACCEPTED SOLUTION

@Sanchez

You mentioned - The question i have is that in the proxy endpoints flows i have two endpoints with a route rule to a different URL as they use a different path completely and their target is set as

https://example.com/reports>

Are you saying you have the same host but the relative paths are different? or both routes are two different targets altogether

Assuming your requirement is to route to the same host, but different paths - You could define multiple target endpoints and reference that in the routerules, both target endpoints can connect to the same target server or different one, and route to a different relative path.

<RouteRule name="target1">
        <TargetEndpoint>TargetEndpoint1</TargetEndpoint>
        <Condition>(proxy.pathsuffix MatchesPath "/example2_report**") and (request.verb = "GET")</Condition>
    </RouteRule>
    <RouteRule name="target2">
        <TargetEndpoint>TargetEndpoint2</TargetEndpoint>
        <Condition>(proxy.pathsuffix MatchesPath "/example1_report**") and (request.verb = "GET")</Condition>
    </RouteRule>

You need to use the <Path></Path> along with the loadbalancer definition

Targetendpoint1

<Path>/users</Path>

TargetEndpoint2

<Path>/todos</Path>

Here is an example. multipletargets-rev3-2018-12-17.zip

Hope this helps

View solution in original post

6 REPLIES 6

Ive tried a few differents options but without success

@Sanchez

You mentioned - The question i have is that in the proxy endpoints flows i have two endpoints with a route rule to a different URL as they use a different path completely and their target is set as

https://example.com/reports>

Are you saying you have the same host but the relative paths are different? or both routes are two different targets altogether

Assuming your requirement is to route to the same host, but different paths - You could define multiple target endpoints and reference that in the routerules, both target endpoints can connect to the same target server or different one, and route to a different relative path.

<RouteRule name="target1">
        <TargetEndpoint>TargetEndpoint1</TargetEndpoint>
        <Condition>(proxy.pathsuffix MatchesPath "/example2_report**") and (request.verb = "GET")</Condition>
    </RouteRule>
    <RouteRule name="target2">
        <TargetEndpoint>TargetEndpoint2</TargetEndpoint>
        <Condition>(proxy.pathsuffix MatchesPath "/example1_report**") and (request.verb = "GET")</Condition>
    </RouteRule>

You need to use the <Path></Path> along with the loadbalancer definition

Targetendpoint1

<Path>/users</Path>

TargetEndpoint2

<Path>/todos</Path>

Here is an example. multipletargets-rev3-2018-12-17.zip

Hope this helps

thank you very much @Nagashree B as this is exactly along the lines of what i wanted to achieve as the default proxy already has a (default) target load balanced and therefore just needed to load balance the flows that were being route ruled also.

Again many thanks as what you provided helped clarify it all for me!

@Sanchez

Glad it helped you.

Again, if your proxy pathsuffix and the target backend paths match, you could use the solution that @Siddharth Barahalikar mentioned.

If the target backend paths are different from the proxy pathsuffix, then you will need to define some variables in the conditional flows and use them in the loadbalancer configuration, or use multiple target endpoints as I suggested.

Hi @Sanchez, first of all, I think your questions need some editing. It is a bit confusing to understand your query. I will give a solution for whatever I understood,

Your Question -
i have two endpoints with a route rule to a different URL as they use a different path completely 

So from you rquestion and sample xml I interpet, you have two endpoints with the same URL but different PATHS.

Here there is no need to use RouteRules or even TargetServers here.

We generally use Route rules, when we want to have multiple different target endpoints in a single proxy. In your case, the endpoint(URL) is the same and only the PATH changes.

This is should be handled with Resources on ProxyEndpoint.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules>


    </FaultRules>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows>
        <Flow name="example1">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/example1_report**") and (request.verb = "GET")</Condition>
        </Flow>
        <Flow name="example2">
            <Description/>
            <Request/>
            <Response/>
            <Condition>(proxy.pathsuffix MatchesPath "/example2_report**") and (request.verb = "GET")</Condition>
        </Flow>
    </Flows>
    <HTTPProxyConnection>
        <BasePath>/sample</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

TargetEndpoint (Without Target Server)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <---- 
    >
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://example.com/reports</URL>
    </HTTPTargetConnection>
</TargetEndpoint>

TargetEndpoint (With Target Server) - add https://example.com to TargetServer

<HTTPTargetConnection>
        <Properties/>
        <LoadBalancer>
            <Server name="example"/>
        </LoadBalancer>
        <Path>/reports{proxy.pathsuffix}</Path>
        <SSLInfo>
            <Enabled>true</Enabled>
        </SSLInfo>
</HTTPTargetConnection>

Thanks @Siddharth Barahalikar as much appreciated and have now managed to resolve this as had multiple different target endpoints which i wanted to load balance.