Implementing API Auto-Discovery for MuleSoft Application Deployed to CloudHub and On-Premise
Join the DZone community and get the full member experience.
Join For FreeIntroduction
API Auto-Discovery is a mechanism that manages an API from API Manager by pairing the deployed application to an API created on the platform. API Management includes tracking, enforcing policies if you apply any, and reporting API analytics. Critical to the auto-discovery process is identifying the API by providing the API name and version.
Prerequisites
To configure auto-discovery for your Mule application, you need to meet the following requirements:
- API must exist in API Manager and configured with either a basic endpoint or a proxy endpoint.
- Mule must be configured to use AnyPoint Platform credentials.
- The auto-discovery element must be configured in your Mule application. This XML element must point to the specific API in the API manager that you want to pair to.
- You need an environment
client_id
andclient_secret
. You can get aclient_id
andclient_secret
from the AnyPoint Platform.
Configuring API Manager
To achieve API Auto-Discovery, you need to configure the API Manager. You can login to the AnyPoint Platform and navigate to API Manager to Manage API from Exchange and select your RAML.
Select Managing type as Basic Endpoint and check on "Check this box if you are managing this API in Mule 4 or above". Then, click Save.
Once you can click on Save, it will give you an API Instance Id, and that will be used for API Auto-Discovery. You will be requiring this API Instance Id to configure your application.
By default, API status is Unregistered. It will become Active, once we deploy an application to the Runtime Manager.
Configuring MuleSoft Application to Enable API Auto-Discovery
You need to add an API Auto-Discovery component in your application using the AnyPoint Platform.
This can be done using a Global configuration of your application. Then, configure your API Auto-Discovery component.
Provide the API Id that you got while configuring API Manager with the Basic Endpoint.
You need to make sure that the below four properties added to your properties file; otherwise API Auto-Discovery will not work.
xxxxxxxxxx
anypoint.platform.analytics_base_uri=https://analytics-ingest.anypoint.mulesoft.com/
anypoint.platform.client_id=89ce5363a43d45809dbd56782b9a73195
anypoint.platform.client_secret=CD7DA80C15dB4Db9b77B27EF05344
anypoint.platform.base_uri=https://anypoint.mulesoft.com/
You can get Client Id and Client Secret from the AnyPoint Platform (Access Management ==> Environments).
After configuring API Auto-Discovery and properties, you need to run the application using AnyPoint Studio and API will become Active in API Manager.
Even once you deploy an application to MuleSoft CloudHub Runtime Manager or MuleSoft On-Premise Runtime, API will be Active in the API Manager.
API Auto-Discovery gives the advantages of applying various policies for your application deployed to CloudHub or on-premise. With this, you can avoid creating proxy applications.
This is how you can implement API Auto-Discovery for your MuleSoft Application.
Opinions expressed by DZone contributors are their own.
Comments