Anypoint Flex Gateway — How to Configure Multiple Replicas

Venkatesh Jujarao
Another Integration Blog
4 min readMay 26, 2023

In my previous articles I have explained about what flex gateway is and how to setup flex gateway in local & connected mode; for more details about my previous articles please refer below links.

In this article I am going to explain about how to configure replicas in the flex gateway.

How to Setup Anypoint Flex Gateway | by Venkatesh Jujarao | Another Integration Blog | Medium

Flex Gateway Setup — Local Mode. This article is an extension of my… | by Venkatesh Jujarao | Another Integration Blog | May, 2023 | Medium

Prerequisite

  • Flex Gateway with single replica.
  • To understand how to do that please refer flex local and connected mode article.

Configure the Replicas (Linux Server)

  • Assumption is that we have already configured flex gateway with single replica with connected mode.
Flex Gateway with Single Replica
  • Locate the registration.yaml file (available under conf.d folder ).

Install WinScp and copy the file to the local.

If you can’t install WinScp then copy the content of file from putty only (open the file in vi editor and copy the content).

Now spin-up the new Linux instance and once its ready follow below steps -

Install Flex Gateway

  • A new Linux instance doesn’t have the flex gateway, so we need to install the flex gateway first.
Before Install — No Conf.d folder available
sudo tee /etc/yum.repos.d/flex-gateway.repo <<\EOF
[flex-gateway]
name = Anypoint Flex Gateway
baseurl = https://flex-packages.anypoint.mulesoft.com/amazonlinux/$releasever/main
gpgcheck = 1
gpgkey = https://flex-packages.anypoint.mulesoft.com/amazonlinux/pubkey.gpg
repo_gpgcheck = 1
enabled = 1
EOF
sudo yum install -y flex-gateway
  • Now we can see the conf.d folder is available in the new Linux instance.
After installation — conf.d folder
  • Now, add the registration.yaml file taken from previous Linux instance to new Linux instance under conf.d folder.

Start Flex Gateway

  • Once we have installed the flex gateway and copied the registration.yaml file then let’s start the flex gateway.
sudo systemctl start flex-gateway
  • Check the status.
systemctl list-units flex-gateway*

Check Replicas Status on Runtime Manager

  • Go to Runtime Manager → Flex Gateway → Name Of your Flex Gateway (in this case demoflxgateway)
Flex Gateway with Mutiple Replicas
  • Now here we can see multiple replicas has been configured.

Now, let’s deploy the application and see how the traffics are getting routed to these replicas. Refer one of my flex gateway local and connected mode article to understand how to deploy the application.

Verify Traffic is Routing to Multiple Instances

Now we have created the replicas, but we need to understand how the traffic will get routed to both replicas so that traffic will be distributed equally, performance will be improved and api would be highly available.

Create a Load Balancer

  • When replicas are configured without any load balancer then client has to write logic from their end to load balance their request accordingly as shown below, which is not an ideal approach.
Mutiple Replicas — Client Calling each time different URL.
  • To avoid this, we need to add a load balancer in front of our replicas so that client need not have to worry about different replicas URL, and they will just make a call to single URL and internally Load Balancer will take care of routing and distributing the load to respective replica URL; as shown in below diagram.
Mutitple Replicas with Load Blancer

Below article will help you to create your own application load balancer in AWS

Guide to Create Elastic Load Balancer in AWS | by Venkatesh Jujarao | May, 2023 | Medium

Call Load Balancer and Verify Request Reaching to Replicas

  • As per below screenshot we can see IP address of replica 1.
  • IP address of replica 2
  • Now in below video closely observer value of origin attribute, we will see the ip’s are getting changed between replica 1 & 2.

Summary

In this article we have learn how to configure multiple replicas in Flex Gateway and using load balancer how to access them with single URL.

FAQ — How to Change the Default Timeout Settings For a Flex Gateway API? | MuleSoft Help Center

--

--