Configuring the API Microgateway
Configuring the API Microgateway locally
Configuring the API Manager
Download WSO2 API Manager.
In the
<API-M_HOME>/repository/conf
 directory of the all-in-one API Manager distribution, open theregistry.xml
file and add the following task,If you are using a distributed setup, change theregistry.xml
file of the Publisher node.<tasks> <task class="org.wso2.carbon.apimgt.micro.gateway.usage.publisher.tasks.UploadedUsageCleanUpTask" name="UploadedUsageCleanupTask"> <trigger cron="0 0 0/1 1/1 * ? *"/> <property key="fileRetentionDays" value="1"/> </task> </tasks>
In the
<API-M_HOME>/repository/conf
directory, open theÂon-premise-gateway.properties
file and enable usage data publishing, as shown below:usage.data.publishing.enabled=true
Configuring the Microgateway
Download the WSO2 API Manager Microgateway.
Open the
<MICRO-GW_HOME>/repository/conf/carbon.xml
file and offset the Microgateway node by 1, as shown below:<Ports> <!-- Ports offset. This entry will set the value of the ports defined below to the define value + Offset. e.g. Offset=2 and HTTPS port=9443 will set the effective HTTPS port to 9445 → <Offset>1</Offset> </Ports>
In the
<MICRO-GW_HOME>/repository/conf/api-manager.xml
file, point the Microgateway’s Key Manager to the default API Manager's Key Manager by modifying the<APIKeyValidator>
section.<APIKeyValidator> <!-- Server URL of the API key manager --> <ServerURL>https://localhost:9443/services/</ServerURL> <!-- Admin username for API key manager. --> <Username>admin</Username> <!-- Admin password for API key manager. --> <Password>admin</Password> <KeyValidatorClientType>WSClient</KeyValidatorClientType> <EnableThriftServer>false</EnableThriftServer> </APIKeyValidator>
To sync the APIs and throttling policies, and upload the usage stats, modify the
on-premise-gateway.properties
file in the<MICRO-GW_HOME>/repository/conf
directory by adding the respective URLs.If you make any changes to the APIs or throttling policies after starting the server, restart the server to make sure the changes are synced.
# Configure the API gateway url below: api.gateway.url=https://localhost:8243 # Configure the publisher url below: api.publisher.url=https://localhost:9443 # Configure the publisher url below: api.admin.url=https://localhost:9443 # Configure the keymanager url below: api.key.manager.url=https://localhost:9443/services # Configure the publisher url below: usage.upload.service.url=https://localhost:9443/micro-gateway/v0.9/usage/upload-file # Configure the publisher url below: api.lifecycle.event.publisher.url=https://localhost:9443/micro-gateway/v0.9/updated-apis
Add the following tasks in the
<MICRO-GW_HOME>/repository/conf/registry.xml
file,<tasks> <task class="org.wso2.carbon.apimgt.micro.gateway.usage.publisher.tasks.APIUsageFileUploadTask" name="APIUsageFileUploadTask"> <trigger cron="0 0 0/1 1/1 * ? *"/> </task> <task class="org.wso2.carbon.apimgt.micro.gateway.usage.publisher.tasks.APIUsageFileCleanupTask" name="APIUsageFileCleanupTask"> <trigger cron="0 0 1 1/1 * ? *"/> <property key="fileRetentionDays" value="35"/> </task> </tasks>
 In the
<MICRO-GW_HOME>/repository/conf/api-manager.xml
file, enable analytics, change the Publisher class, and skip event receiver connection, as shown below:<Analytics> <!-- Enable Analytics for API Manager → <Enabled>true</Enabled> <!-- API Usage Data Publisher. --> <PublisherClass>org.wso2.carbon.apimgt.micro.gateway.usage.publisher.APIMgtUsageFileDataPublisher</PublisherClass> <!-- Below property is used to skip trying to connect to event receiver nodes when publishing events even if the stats enabled flag is set to true. --> <SkipEventReceiverConnection>true</SkipEventReceiverConnection> </Analytics>
Add the following entries to the
log4j.properties
file in the<MICRO-GW_HOME>/repository/conf
directory.log4j.logger.org.wso2.carbon.databridge.agent.endpoint.DataEndpointConnectionWorker=FATAL log4j.logger.org.wso2.carbon.databridge.agent.endpoint.DataEndpointGroup=FATAL
Modify the
jndi.properties
file in the<MICRO-GW_HOME>/repository/conf
directory using the Microgateway port.connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientid/carbon?brokerlist='tcp://localhost:5673' connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/test?brokerlist='tcp://localhost:5673'
Test the Microgateway locally
- Start the API Manager server.
- Publish and invoke a few APIs.
- Start the Microgateway server.
Invoke the deployed APIs.
Change the access token accordingly.curl -X GET "https://172.17.0.1:8244/pizzashack/1.0.0/menu" -H "accept: application/json" -H "Authorization: Bearer 302a4a81-5318-3ad8-82f3-82f393c0ad0e" -k
- If the default distribution has Analytics enabled, you see statistics in the API Manager Publisher and Store.
Configuring the Microgateway in the Cloud
Follow the steps in the Working with Hybrid API Management page with the following modifications for each step.
Step 1 - Instead of the On-Prem Gateway, use the Microgateway zip file.
Step 2 - Run the cloud-init.sh
or cloud-init.bat
scripts in the <MICRO-GW_HOME>/bin
directory.