I want to design a proxy and retrieve the backend url from kvm

I want to design a proxy that retrieves backend url from kvm ...

0 12 677
12 REPLIES 12

If your backend host is static but the path is varying, you could use a load balancer for the host and retrieve the path from your KVM as a variable that gets passed into the path parameter

Load balancer: https://docs.apigee.com/api-platform/deploy/load-balancing-across-backend-servers

Hi @HIMADRI BHATTACHARJEE,

There are generally two ways to make a target backend configurable:

  1. Use a Target Server that is configured per env and set variables for path and suffix via KVM, as noted above.
  2. Use an Assign Message or Javascript to set the target.url variable directly.

Using option 2, you could look up the complete target URL from a KVM and set it in the Target PreFlow. For example, given the variable in <Ref> is populated from a KVM:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="AM-Target-URL">
    <DisplayName>AM-Target-URL</DisplayName>
    <!-- Put in target pre flow -->
    <AssignVariable>
        <Name>target.url</Name>
        <Ref>flow.target.scheme_host_basepath_and_suffix</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

NOTE: you must set target.url in the Target flow and that the Target Server <URL> is not used.

    <HTTPTargetConnection>
        <!-- URL gets overwritten by AM-Target-URL -->
        <URL>https://dummy.url</URL>
    </HTTPTargetConnection>

Please explain it is not clear for a newbie...

Sometimes it's better to learn by doing. Here are the steps and links to documentation for the simple case in option 2.

  1. Using the UI, create a KVM and set the full path for the target URL with key scheme_host_basepath_and_suffix.
  2. In your proxy, in the Target PreFlow
    1. Add a KVM policy to lookup the value of the KVM entry and set it to flow.target.scheme_host_basepath_and_suffix
    2. Add an Assign Message policy as shown above
  3. Trace your proxy to see the values being populated.

Notice the difference between the request URL "/echo/params" and the target URL shown in the trace image.

8773-screen-shot-2019-07-09-at-93514-am.png

Try it out, you'll undoubtedly will learn something new.

Do I give a target when i create the proxy or make it no target?@Kurt Googler Kanaskie

As per Kurt's note, you need to set a target. This can be any temporary address that will later be overridden.

Please respond via comments, not as a new answer.

Yes, provide a target endpoint as per

    <HTTPTargetConnection>
        <!-- target.url gets overwritten by AM-Target-URL -->
        <URL>https://dummy.url</URL>
    </HTTPTargetConnection>

Using a Target Server you could use:

    <HTTPTargetConnection>
        <LoadBalancer>
            <Server name="parameterize-target-endpoint"/>
        </LoadBalancer>
        <!-- Separate basepath and suffix
        <Path>{flow.target.basepath}/{flow.target.suffix}</Path>
        -->
	<!-- both in one variable -->
        <Path>{flow.target.basepath_and_suffix}</Path>
    </HTTPTargetConnection>

I am not able to understand how we are going to override it?I am getting a 503 error?dane knezic

See above and please remember to use "Add comment"

@Kurt Googler Kanaskie

seturldynamicallyfromkvm-rev3-2019-07-24.zip . Sorry not able to make it work.Not able to assign target endpoint from assign message policy.

I have attached the proxy.Please help....

Hi @HIMADRI BHATTACHARJEE,

I have fixed your proxy now you can see the target url is coming from KVM.

8898-seturldynamicallyfromkvm-rev3-2019-07-24-rev3.zip

you were not configuring the KVM policy properly, take a look at the sample i have fixed.

1. I have done two things. Moved KVM in proxy preflow.

2. Fixed the variable naming

Here are the steps for you to test this proxy.

- Create KVM with name backendtargetservers

- Create a key value in the KVM backendtargetservers

key - scheme_host_basepath_and_suffix

value - http://httpbin.org/get

screen-shot-2019-07-24-at-50037-pm.png

Upload the proxy and deploy that. you will see screen-shot-2019-07-24-at-50152-pm.png

Thanks it works...