API Management and Flex Gateway in Connected Mode

Rachana M
5 min readNov 24, 2022

--

Videos are available at the page end.

Anypoint Flex Gateway is a lightweight standalone gateway that can serve as a proxy for any API, including non-Mule APIs.

It can run on major Linux distributions, as a containerized application using a MuleSoft supported OCI image, and as a Kubernetes-native ingress controller or API gateway.

Anypoint Flex Gateway has a small footprint that allows for installation on the same resource, cluster, and network as the upstream target APIs, delivering sub-second response times.

Flex Gateway is a performant API gateway that can secure both Mule and non-Mule APIs. It is easily integrated into CI/CD workflows while offering enterprise security and manageability. It can be run on a public cloud or on-prem.

We can run Flex Gateway in two different modes:

  • Connected Mode: Run Flex Gateway in Connected Mode if we want it fully connected to the Anypoint control plane for centralized management, observability, and security.
  • Local Mode: Run Flex Gateway in Local Mode if we want to run it mostly disconnected from the Anypoint control plane and manage it with locally stored declarative configuration files.

Install Anypoint Flex Gateway in Connected Mode:

Pre-requisite : Deploy an mule application on Docker container and make sure it is connecting (please follow this video , if you are new how to deploy mule application on Docker). I have deployed my mule application that is listening port 8092 on docker port 5000

Mule Application on Docker

Here are the steps that needs to be followed for Flex Gateway.

1) Create an Empty folder of your desired naming convention. Here Ihave created flexgateway as my empty folder.

Empty Folder

2) Now let's go to Anypoint Runtime Manager and select Flex Gateways then click on Add Gateway.

Runtime Manager

3) Since I have a mule application on Docker Container, I am selecting docker.

Docker Env

4) We will be getting few of the commands to setup flex gateway for Docker. Copy all the below commands into notepad then let's start one by one .

Steps to configure Docker

4-a) First we need open a command prompt to pull mulesoft/flex-gateway with below command.

C:\Users> docker pull mulesoft/flex-gateway

Step 1

4-b) Copy the second command remove -u $UID, replace the $(pwd) with the empty folder create in Step A and replace <gateway-name> with your preferred name.

Eg: docker run — entrypoint flexctl -v “C:\Users\mrach\flexgateway”:/registration mulesoft/flex-gateway register — organization=9cd8e50f-de6f-47a4-bf9c-f2d529819077 — token=7be47a9f-07c6–482d-abd9–3fbafe02ce36 — output-directory=/registration — connected=true mule-demo-gateway-docker2

Points To Remember: please copy the command from your Anypoint platform page as organization and token differs whenever you try to add new gateway.

Step 2

4-c) Copy the third command replace the $(pwd) with the empty folder create in Step A and remove backslash (\) from command.

Eg: docker run — rm -v “C:\Users\mrach\flexgateway”:/usr/local/share/mulesoft/flex-gateway/conf.d -p 8081:8081 mulesoft/flex-gateway

Points to Remember: This creates single replica in gateway, if you 2 or more please repeat 3rd step with different port (-p 8082:8082)

Step 3

5) Once the above steps are successful, we can see the container with our mulesoft/flex-gateway with 8081 port and mule-flex-gate1 in Runtime Manager.

Runtime Manger with mule-flex-gate1

6) Now lets add the api to our flex-gateway, Go to Api Manager and click Add API.

API Manager

7) As next step, select Flex Gateway which we created in the previous steps(mule-flex-gate1) then click next.

8) Here select Create new API and fill the required info as below.

9) In this step, add below details

a) API Instance Lable: Any name of your choice.

b) Implementation URL is important: get Ip address of your system(run ipconfig in command prompt) and add the port number what we gave for the mule application deployed on Docker container ( i.e. 5000)

c) Schema : HTTP

d) Port: provide the port that we used to create the gateway (i.e. 8081 in my case)

10) Once all information is filled, click on save and deploy.

11) Once Deployed we can see API Status as Active and Runtime Target as flex-gateway that we created.

Deployed API on Flex gateway

12) In-order to test please provide the below endpoint in browser

Response from gateway

Deploy Mule Application on Docker from Anypoint Platform — YouTube

API Management and Flex Gateway in Connected Mode — YouTube

API Management and Flex Gateway (Apply Policies) — YouTube

--

--

Rachana M

3x Certified MuleSoft Developer | MCD, MCPA,MCIA | Mulesoft Mentor| New to Blogs writing