Microgateway proxies and multiple environments

Former Community Member
Not applicable
2 2 2,015

Abstract

How Microgateway proxies can point to different target endpoints in different environments?

Problem

Microgateway reads proxy name, basePath and target endpoint from API Proxies hosted in Edge. When a Microgateway is configured for an environment it exposes all (default behavior) the edgemicro_* proxies deployed on that environment.

Typically, target endpoints are different for each environment. When the same proxy is deployed to different environments, the target endpoints don't change. So how do you handle this with Microgateway?

Approach

If you were only working Apigee Edge, then you can leverage target servers or route rules and even some custom JavaScript to dynamically route API requests to different backend based on the environment. Microgateway does not have access to target server info or route rules.


Option 1

One could create a proxy for each environment and deploy that proxy only to that environment. For example, edgemicro_dev_sample1 (with target endpoint to https://sample1.dev.example.com) and edgemicro_test_sample1 (with target endpoint to https://sample1.test.example.com).

With this approach, you are creating a lot of proxies and have to be careful to know which environment you want to deploy a proxy to. While I'm not a fan of this approach, it is certainly doable.

Option 2

In this approach we rely on an external service catalog that stores endpoints for each environment. One could leverage tools like Apache Consul or Netflix's Eureka for this. But in this article, I will leverage Apgiee Edge itself.

  1. Create a environment scoped KVM. In this example we'll call it 'microgateway-router'. The hashmap in the KVM will contain name = "proxyName_revision" and value = "target endpoint". For example: name=edgemicro_sample1_1, value=https://sample1.dev.example.com
  2. Since the KVM is environment scoped, each environment will have a different target endpoint for the same key (ex: edgemico_sample1_1 might map to https://sample1.test.example.com)
  3. Create an Apigee Edge proxy that takes a proxy name and revision as a parameter and returns the endpoint (from the KVM entry).
  4. Finally, apply a custom plugin like this (https://github.com/srinandan/router) which applies the routing logic.

Routing Logic

Each Microgateway instance is configured to use the custom plugin. One of the configuration parameters for the plugin is to setup the endpoint lookup URL (for the Apigee Edge proxy).

  1. Map incoming request to a proxy name.
  2. Look up proxy name in local cache for routing rule. If missing, call endpoint lookup (Apigee Edge proxy) and get the endpoint. Store the endpoint in cache and route the request.
  3. If cache was present, use the target endpoint from cache and route the request.
  4. If the cache key and the endpoint lookup failed, use the original target endpoint
Comments
gupta_pratik
New Member

Hi @Srinandan Sridhar.....thanks for this article...an informative one

mohamedferchich
New Member

Can you please.https://community.apigee.com/users/2485/ssridhar.html add a video to show how to deploy the new plugin in edgemicro

Version history
Last update:
‎10-24-2017 09:08 PM
Updated by:
Former Community Member