Apigee Shared Flow

Reading Time: 4 minutes

Hi All, In this blog, I’ll be talking about Apigee Shared Flow. Those who are not very familiar with what Apigee is, let me give a brief description of the same. And, you can read more on this from the links provided further.

Apigee Edge is a platform that helps in creating and managing API proxies. You can consider API proxy as a face for your backend services. Rather than directly exposing your service endpoints, you can create an API proxy and provide that to the client who wants to utilize your application’s functionality.

An API proxy, not only acts as an intermediate layer between the client (e.g. app, web page, etc) and your service but also makes it easy to add certain features like authentication, traffic management, logging, etc. which are otherwise difficult to add on the service level. To read more about an API proxy, how it works and how to create one, you can check here.

Now, let’s think of a scenario where you have some number of API proxies for your backend services and you want to add a feature (in terms of Apigee, a feature can be a condition/policy attached to the flows of the proxy) which is common to all or may be used in more than one proxy. And, now if we go on to add that feature in each of our proxies, that is definitely a redundant effort.

Don’t worry, Apigee is here to help us in such a scenario by providing a wonderful feature – Shared flow.

As the name says, Shared flow is a reusable component which can be created at one place and used by multiple proxies during their execution flow as long as the proxies and shared flow lie in the same environment.

The best part is – its very simple to create a shared flow. Those who know how to create an API proxy can easily create a shared flow. A shared flow is similar to an API proxy, except the fact that it is not an endpoint and can be called either from an API proxy or from other shared flows, and not from outside.

How to create a Shared Flow?

1. Login to your Apigee Edge account.

2. Go to the Develop > Shared Flow tab.

3. On the top-right, you will see a +Shared Flow button, click on it to start creating one.

4. There are two options to build a shared flow – Creating an empty shared flow OR Importing an existing shared flow from a zip archive. Select one.

5. The next step is to provide the name and description of the shared flow. If you have selected the import option, then browse through your system and upload the zip.

6. Your empty shared flow is created, you can now attach the policies to it, just like you do with a proxy by moving to the Develop option on the right. Or if you have imported the shared flow, then the policies are already set.

Your shared flow will look something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SharedFlow name="default">
  <Step>
    <!-- You can add any policy in these steps -->
    <Name>Assign-Message-1</Name>
    <Condition>
      <!-- Add the condition when you want the policy to execute -->
    </Condition>
  </Step>
</SharedFlow>

Screenshot from 2019-04-05 13-22-53

7. Select the environment on which you want to deploy your shared flow, and now you are ready to start using the shared flow.

How to use a Shared Flow?

There are two ways in which you can use a shared flow:

1. Using FlowCallout Policy.

You can add a shared flow via Flow Callout Policy in your proxy or another shared flow, and attach it to the proxy execution flow.

Screenshot from 2019-04-05 13-27-49

Adding a step in your proxy flow(PreFlow, PostFlow, etc) will look like:

<Step>
  <Name>FlowCallout.SharedFlow1</Name>
<Step>

 

2. Attaching it using Flow Hook.

If you want a shared flow to run before processing request, or after receiving the response for every proxy in an environment, then attaching the shared flow using a flow hook is the best option.
To attach a shared flow to a flow hook, you must be an organization admin.

Flow hooks let you execute shared flows for all proxies in an environment and there are 4 flow hooks:

  1. Pre-proxy Flow Hook – executes the attached shared flow before calling the proxy endpoint.
  2. Pre-target Flow Hook – executes the attached shared flow before sending the request to the target server.
  3. Post-target Flow Hook – executes the attached shared flow after receiving the response from the target server.
  4. Post-proxy Flow Hook – executes the attached shared flow after the proxy endpoint and before sending the response to the client.

Go to the Admin > Environments > Flow Hooks and add shared flow to any of the 4 flow hooks.

Screenshot from 2019-04-05 13-31-27

Point to remember: You can attach at most one shared flow for a particular Flow Hook. You can, however, attach the same shared flow to multiple flow hooks.

How to determine whether the shared flow is executed or not?

You don’t have an option of Tracing in a shared flow. So, To check whether the shared flow is working, start tracing the proxy endpoint where you have attached your shared flow.

Within the transaction map, check if the FlowCallout policy is executed or not. You will see something like this for your shared flow:

Screenshot from 2019-04-04 16-09-08

The grey box contains the steps of your shared flow.

That’s all about the shared flow.

Now, start building your own shared flow, and let me know how much this blog is helpful to you by writing in the comments section below.

References:

Happy Blogging! 🙂


Knoldus-blog-footer-image

Written by 

I am a Software Consultant, having experience of more than 1 year. I am well versed with Object Oriented Programming Paradigms having good command of programming languages like Scala, Java & C++ and also skilled in building the microservices architecture based application using Lagom, Cassandra, Elasticsearch and many more. My hobbies include reading novels, writing blogs, drawing, listening to music.

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!