DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Microservices With Apache Camel and Quarkus
  • Understanding Dependencies...Visually!
  • Competing Consumers With Spring Boot and Hazelcast
  • Microservices With Apache Camel and Quarkus (Part 3)

Trending

  • Microservices With Apache Camel and Quarkus
  • Understanding Dependencies...Visually!
  • Competing Consumers With Spring Boot and Hazelcast
  • Microservices With Apache Camel and Quarkus (Part 3)
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Integration Builder: Sub-Flow Example

Integration Builder: Sub-Flow Example

In this article, let's look at a sub-flow example and see how to use it.

Leor Brenman user avatar by
Leor Brenman
·
Dec. 25, 19 · Tutorial
Like (3)
Save
Tweet
Share
16.80K Views

Join the DZone community and get the full member experience.

Join For Free
Man painting ceiling in building
Integration Builder

Sub-flows are an Axway Integration Builder step type. Sub-flows are useful to encapsulate functionality in a reusable component (flow) and help you create DRY flows (Don't Repeat Yourself). They are basically flows that are called from another flow and can be viewed as a function.

In this post, we'll review the steps to create and use a sub-flow in another flow as well as how to pass in variables and arguments and access the sub-flow response.

The basic steps are as follows:

  • Create your sub-flow as you would any flow and set the trigger type to manual; you don't need to create a flow instance
  • The sub-flow can access any passed in arguments using trigger.args and config.varName
  • Create your parent flow and use the sub-flow step to incorporate your sub-flow into your parent step
  • The parent step should prepare the arguments and any variables to pass into the sub-flow in a step prior to the sub-flow step
  • The parent flow can access the response of the sub-flow
You might also enjoy:  API Builder: A Simple CI/CD Implementation – Part 1

Sub-Flow

A simple flow, which we'll use as a sub-flow, is shown below:

The JS Step, consoleLog simply prints some info to the console and also computes a response as follows:

Java
xxxxxxxxxx
1
 
1
console.log(trigger);
2

           
3
console.log(config);
4

           
5
console.log(config.parentFlowVariable);
6

           
7
done({value:trigger.args.inputVal*2});


We'll look at the console for a sample execution later but for now, what's important is the following:

  • We are printing the trigger, which will contain arguments passed in from the parent flow
  • We are printing the config, which will contain variables passed in from the parent flow AND any parent flow variables

  • We are accessing a variable, parentFlowVariable, that is NOT passed in from the parent flow as follows:

Java
xxxxxxxxxx
1
 
1
config.parentFlowVariable 

Note that this is to show that the sub-flow has access to any parent flow variables whether they are passed in or not. This is not best practice since the sub-flow shouldn't know anything about the parent flow scope.

    We are accessing an argument, inputVal, passed in from the parent flow a follows:
Java
xxxxxxxxxx
1
 
1
trigger.args.inputVal 
    We are computing a response (doubling the inputVal) for the parent flow:
Java
xxxxxxxxxx
1
 
1
done({value:trigger.args.inputVal*2}); 

Use the Sub-Flow

Let's create a flow and use the Sub-flow. My simple test flow is shown below:

You can find the sub-flow step at the bottom of the step list when you add a step:

The first thing we can look at is how we prepared to call the sub-flow in the prepareSubflow JS Script step:

JavaScript
xxxxxxxxxx
1
15
 
1
done(
2
  {
3
    args:
4
    {
5
      inputVal:10,
6
      inputArray: [1,2,3,4,5],
7
      inputStr: "Hello World"
8
    },
9
    subFormulaConfigs:
10
    {
11
      var1: '11111',
12
      var2: '2222'
13
    }
14
  }
15
);

You can see we are creating an object with two properties: args and subFormulaConfigs. We construct our arguments in the args object and the variables in the subFormulaConfigs object.

The sub-flow step is shown below:

It has a step name, SubFlowStep and the ID of the sub-flow created above, 30810. It also contains the arguments and variables computed in the prepareSubflow JS Script step above it:

  • ${steps.prepareSubflow.args}
  • ${steps.prepareSubflow.subFormulaConfigs}

The last step in the test flow is a consoleLog JS Script step to print the results of the sub-flow, value:

Java
xxxxxxxxxx
1
 
1
console.log(steps.SubFlowStep.value); 

View the Results

Let's look at the execution log to see how arguments and variables were passed and results computed and accessed.

Here is the log for the prepareSubflow step.

You can see the arguments and variables being created.

Here is the log for the SubFlowStep step:

You can see 3 items in the console:

    The trigger that contains the arguments:
Java
xxxxxxxxxx
1
13
 
1
{
2
  "args": {
3
    "inputVal": 10,
4
    "inputArray": [
5
      1,
6
      2,
7
      3,
8
      4,
9
      5
10
    ],
11
    "inputStr": "Hello World"
12
  }
13
}
    The config which contains the variables passed in as well as parent flow variables:
Java
xxxxxxxxxx
1
 
1
{
2
  "parentFlowVariable": 33,
3
  "var1": "11111",
4
  "var2": "2222"
5
}
    The parentFlowVariable value accessed directly:
Java
xxxxxxxxxx
1
 
1
33

We can also see the value that was computed and returned (20).

This same value is printed in the final parent flow step shown below:

Summary

In this post, we looked at the mechanics of creating and using an Integration Builder Sub-flow step to help create cleaner, more maintainable flows.

Further Reading

Configuring the Ground: How to Install and Configure an API Builder Data Connector

Create an API Builder Multi-Container App Using Docker (Part 1)

Flow (web browser) Integration

Published at DZone with permission of Leor Brenman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Microservices With Apache Camel and Quarkus
  • Understanding Dependencies...Visually!
  • Competing Consumers With Spring Boot and Hazelcast
  • Microservices With Apache Camel and Quarkus (Part 3)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: