Publish Through Multiple API Gateways¶
If you need to distribute the Gateway load that comes in, you can configure multiple API Gateway environments in WSO2 API Manager to publish to a single Developer Portal. This 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 Developer Portal. When you publish an API through multiple Gateway environments, the APIs in the API Developer Portal will have different server hosts and ports.
Step 1 - Publish an API via Multiple API Gateways¶
Follow the instructions below to configure and publish to multiple Gateways.
In this guide, let's set up three (3) WSO2 API Manager (WSO2 API-M) instances on the same server.
- Instance 1 : Acts as the node that provides the Publisher, Developer Portal, and the Key Manager functionality.
- Instance 2 : Acts as a production Gateway node.
- Instance 3 : Acts as a sandbox Gateway node.
In a typical production environment, the Gateways will ideally be in separate servers.
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/deployment.tomlfile 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/deployment.tomlfile 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/deployment.tomlfiles 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.
[apim.key_manager] service_url = "https://localhost:9443/services/" username = "admin" password = "admin" [apim.throttling] service_url = "https://localhost:9443/services/" throttle_decision_endpoints = ["tcp://localhost:5672"]
You are done configuring the two API Gateway instances.
<API-M_HOME>/repository/conf/deployment.tomlfile in the first API Manager instance, add two API Gateway environments by adding two
[[apim.gateway.environment]]sections and comment out the
[[apim.gateway.environment]]section that comes by default.
This is done to point to the two API Gateway instances from the first instance.
There can be different types of environments, and the allowed values are
An API deployed on a
productiontype Gateway will only support production keys.
- An API deployed on a
sandboxtype Gateway will only support sandbox keys.
- An API deployed on a
hybridtype Gateway will support both production and sandbox keys.
api-consoleelement specifies whether the environment should be listed in API Console or not.
- The Gateway environment names must be unique.
[[apim.gateway.environment]] name = "Production Gateway" type = "production" display_in_api_console = true description = "Production Gateway Environment" show_as_token_endpoint_url = true service_url = "https://localhost:9444/services/" username= "admin" password= "admin" http_endpoint = "http://localhost:8281" https_endpoint = "https://localhost:8244" [[apim.gateway.environment]] name = "Production and Sandbox" type = "hybrid" display_in_api_console = true description = "Hybrid Gateway Environment" show_as_token_endpoint_url = true service_url = "https://localhost:9445/services/" username= "admin" password= "admin" http_endpoint = "http://localhost:8282" https_endpoint = "https://localhost:8245"
If you have multiple Gateways that support one type of key (e.g., when there are two Gateways that support the production keys, as seen in the above code snippet.), the environments you add via the
<API-M_HOME>/repository/conf/deployment.tomlfile will be visible in a drop-down list of the API Try Out tab, which is in the Developer Portal of instance 1. This allows subscribers to send API requests to any selected Gateway.
To stop a given Gateway environment from being displayed in the API Try Out tab, you can set the
apim.gateway.environmentelement, which is in the
[[apim.gateway.environment]] display_in_api_console = false
Start all the WSO2 API-M instances.
Make sure to start instance 1 first before starting the other two instances.
Sign in to the API Publisher in the first WSO2 API-M instance and click to edit an API.
Click Manage, and expand the API Gateways section.
Note that the two Gateway environments are listed there.
Select both Gateways and click Save and Publish in order to be able to publish to both the Gateways that correspond to the API.
In the Overview tab that corresponds to the API, note that it has two sets of URLs for the two Gateway instances:
You have successfully published an API to the API Developer Portals through multiple Gateway environments.
Step 2 - Generated the keys for the applications¶
Use the following sample cURL command to generate an access token for the Gateway URL of the initially published Gateway Environments, which was listed in API Publisher in step 8, using the Password Grant type.
Change the Gateway URL based on the Gateway that you need to publish the API.
If you wish to use the API-M pack that you used as the first instance to try-out other tutorials, please ensure to delete the API Gateway configurations that you added in step 5, and uncomment the default
[[apim.gateway.environment]] configurations in the