Implementing API Autodiscovery for MuleSoft application deployed to CloudHub and on premise

  • March 17, 2020

API Autodiscovery 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 Autodiscovery process is identifying the API by providing the API name and version.

Prerequisites

To configure Autodiscovery for your Mule application you need to meet the following requirements:

  • API must exist in API Manager, configured with either a basic endpoint or a proxy endpoint.
  • Mule must be configured to use AnyPoint Platform credentials.
  • The Autodiscovery element must be configured in your Mule application. This XML element must point to the specific API in API manager that you want to pair to.
  • Need environment client_id and client_secret. You can get client_id and client_secret from AnyPoint Platform.

Configuring API Manager

To achieve API Autodiscovery, you need to configure API Manager. You can login to AnyPoint Platform and navigate to API Manager => Manage API from Exchange and select your RAML.

Configuring API Manager

Select Managing type as Basic Endpoint and “Check this box if you are managing this API in Mule 4 or above.“ Click Save.

Once you can click save, it will give you API Instance Id and that will be used for API Autodiscovery. You will need this API Instance Id to configure in your application.

By default, API status is Unregistered. It will become Active, once we deploy an application to the Runtime Manager.

API Instance Id to configure

Configuring MuleSoft Application to enable API Autodiscovery

You need to add an API Autodiscovery component in your application using AnyPoint Platform.

Add an API Auto Discovery component

This can be done using Global configuration of your application. Configure API Autodiscovery component.

Configuring API Manager with Basic Endpoint

Provide the API Id you got while configuring API Manager with Basic Endpoint.

You need to add these four properties to your properties file otherwise API Autodiscovery will not work.

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 AnyPoint Platform (Access Management ==> Environments).

Run the application using AnyPoint Studio

After configuring API Autodiscovery 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 API Manager.

API Autodiscovery gives the advantages where you can apply various Policies for your application deployed to CloudHub or on premise. You can avoid creating proxy applications.

Timezone API

Video link: https://youtu.be/JaWvSuKn__8

— By Jitendra Bafna