You can configure multiple API Gateway environments in WSO2 API Manager that publish to a single API Store when you require distributing the gateway load comes in. It helps you to distribute the API Gateway load to multiple nodes and also gives you some logical separation (e.g., production vs. sandbox) between the APIs in the API Store. When you publish an API through multiple Gateway environments, the APIs in the API Store will have different server hosts and ports.
The steps below explain how to configure and publish to multiple Gateways. In this guide, we set up three (3) WSO2 API Manager (WSO2 API-M) instances in the same server. In a typical production environment, the Gateways will ideally be in separate servers.
- Instance 1: Acts as the node that provides the API Publisher, Store, and the Key Manager functionality.
- Instance 2: Acts as a production Gateway node.
- Instance 3: Acts as a sandbox Gateway node.
Copy the WSO2 API Manager (WSO2 API-M) product pack into three (3) separate folders.
Let's add offsets to the default ports of the two Gateway instances. A port offset ensures that there are no port conflicts when more than one WSO2 product runs on the same server.
<API-M_HOME>/repository/conf/carbon.xmlfile in the second API Manager instance, and add an offset of 1 to its default port. This increments its default server port, which is 9443, by 1.
<API-M_HOME>/repository/conf/carbon.xmlfile in the third API Manager instance and add an offset of 2 to its default port. This increments its default server port, which is 9443, by 2.
<API-M_HOME>/repository/conf/api-manager.xmlfiles in the second and the third API Manager instances and set the
This is done to disable the thrift server in the two Gateway instances. Thrift server is needed for the Key Manager functionality. It is not needed in the Gateway instances.
<API-M_HOME>/repository/conf/api-manager.xmlfiles in the second and the third Gateway instances and change the following.
This is done for the two Gateway instances to be able to communicate with the Key Manager that is in the first API Manager instance.
<API-M_HOME>/repository/conf/api-manager.xmlfiles in all the Gateway instances and uncomment the following configuration:
You are done configuring the two API Gateway instances.
<API-M_HOME>/repository/conf/api-manager.xmlfile in the first API Manager instance, add two API Gateway environments under the
<Environments>element, and comment out the
<environment>element that comes by default.
This is done to point to the two API Gateway instances from the first instance.
Tip: The Gateway environment names must be unique.
Tip: The environments you add here will be visible in a drop-down list in the API Console tab of the API Store. It allows subscribers to send API requests to any selected Gateway.
To stop a given Gateway environment from being displayed in the API Console tab, you can set the
<environment>element in the
<Environment type="production" api-console="false">.
- Start all the WSO2 API-M instances.
- Sign in to the API Publisher in the first WSO2 API-M instance and choose to edit an API.
- Navigate to the Manage tab, expand the Gateway Environments section.
Note the two Gateway environments listed there.
In a typical production setup, you will publish the API to the sandbox Gateway first, and thereafter publish it to the production Gateway. In this case, let's publish to both.
- Select both Gateways and Save and Publish the API.
- Sign in to the API Store (of the first instance) and click the API to open it.
- In the API's Overview tab, note that it has two sets of URLs for the two Gateway instances:
You have published an API to the API Stores through multiple Gateway environments.
If you have published your API through more than one Gateway,
When you have generated keys for the Applications, the sample cURL command shows how to generate an access token using the Password Grant type provides the Gateway URL of the first published Gateway Environments listed in API Publisher as shown in the step 10.
Change this gateway URL according to the Gateway that you want to publish the API if you are using this Curl command to generate acces tokens.
If you wish to use the API-M pack that you used as the first instance to tryout other tutorials, please ensure to delete the API Gateway configurations that you added in step 6, and uncomment the default
<Environment> configurations in the