0
votes

I have one API replicated in multiple backends. I don't have any condition that can differentiate between backends. I tried to use dynamic endpoints and change the message mediation flow: https://apim.docs.wso2.com/en/latest/deploy-and-publish/deploy-on-gateway/api-gateway/message-mediation/changing-the-default-mediation-flow-of-api-requests/ However, the only difference between requests is the IP address of the backend server:

https://{uri.var.host}/resource

I'm thinking to create every time the API and change the endpoint address but this solution can be complex as I will have the same API replicated many times (around 100) in the wso2 api manager. There is any other solution that can fit my use case?

1

1 Answers

0
votes

We can make use of Dynamic Endpoints to achieve your requirement. But, it is required that the client applications need to either send a param or a Header to filter and construct the BE server URL in the mediation sequence to route the requests in the API Manager.

If the client applications can send a header specifying a unique (server) name or any other value while invoking the API, we can use the key to filter (or perform a switch case operation) and construct the BE server URL in the mediation sequence and route them to the respective BE services. Refer to the following Docs for more information.

A sample mediation sequence will be as follows (the client application will be sending a header named as X-ServerName with a name)

<sequence xmlns="http://ws.apache.org/ns/synapse" name="dynamic-endpoint-seq">
    
    <!-- extract the name from the header -->
    <property name="server_name" expression="$trp:X-ServerName" />

    <!-- switch case for all applicable names -->
    <switch source="$ctx:server_name">
        <case regex="server-one">
            <property name="service_ep" value="http://server-one-ip/resource"/>
        </case>
        <case regex="server-two">
            <property name="service_ep" value="http://server-two-ip/resource"/>
        </case>
        <default>
            <property name="service_ep" value="http://server-default-ip/resource"/>
        </default>
    </switch>

    <header name="To" expression="get-property('service_ep')"/>
</sequence>