This documentation is for WSO2 API Manager 1.8.0 View documentation for the latest release.
Page Comparison - API Gateways with Dedicated Backends (v.6 vs v.7) - API Manager 1.8.0 - WSO2 Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: https://support.wso2.com/jira/browse/WSODOCINTERNAL-621

...

  1. Start WSO2 API Manager Server which includes the API Publisher Component and create an API.
  2. Go to the implement stage of the API and replace Host and Port of the API endpoint with {uri.var.host} and {uri.var.port} respectively as shown below.
  3. Save and Publish API. 

    Tip

    Refer Create and Publish an API for more information on creating and Publishing the API.

  4. Create a java class extending the AbstractMediator class of org.synapse.core as below and create the jar file out of it.

    Code Block
    import org.apache.synapse.MessageContext;
    import org.apache.synapse.mediators.AbstractMediator;
    
    public class EnvironmentResolver extends AbstractMediator {
    
        @Override
        public boolean mediate(MessageContext messageContext) {
    
            String host = System.getProperty("environment.host");
            String port = System.getProperty("environment.port");
    
            messageContext.setProperty("uri.var.host", host);
            messageContext.setProperty("uri.var.port", port);
    
            return true;
        }
    
        @Override
        public boolean isContentAware(){
            return false;
        }
    }
    Note

    We use Java system properties which will be set at the server start-up process of each Gateway to resolve the variables which are defined as properties in this sequence.

  5. Add the created jar into <AM_HOME>/repository/components/lib folder of each Gateway. You can download a sample jar file created from here.

  6. Add following sequence to <AM_HOME>/repository/deployment/server/synapse-configs/sequences folder of each Gateway.

    Code Block
    <sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--In">
            <class name="org.wso2.carbon.env.EnvironmentResolver"/>
    </sequence>
    Note

     org.wso2.carbon.env.EnvironmentResolver is the fully qualified name of the class that contains the code responsible for converting system variables into properties. It is a special class we created which needs to be extended from the org.apache.synapse.mediators.AbstractMediator class and requires overriding the 'mediate' function. 

  7. Execute the following command when starting up each Gateway to set the system variables at the server start up from within the <APIM_HOME>/bin directory by replacing the following values.

    <ip_of_backend_environment><port_of_backend_environment>
    host IP of the Gatewayport where the Gateway is running in the dedicated machine or VM
    Code Block
    ./wso2server.sh -Denvironment.host=<ip_of_backend_environment> -Denvironment.port=<port_of_backend_environment>


    Now the Gateways have started with the dedicated backend host/port combinations.

  8. Invoke the API.

...