Preface
The TIBCO Flogo for TIBCO BusinessWorks Developers series of articles aims to familiarize BusinessWorks developers with TIBCO Flogo in order to better utilize these complementary technologies. Each article is focused on a specific key common behavior or feature that is often used in a BusinessWorks project. It takes that common behavior and replicates that in Flogo.
Iteration
In this article, we will take a look at iterations. There are multiple different iteration types within BusinessWorks that are commonly used. We will touch on each of these.
Group-While-True
This is the iteration behavior of While-True enclosed within a group. What this does is the activities within the group will repeat its execution as long as the condition is true. Do note that there is another similar iteration behavior called Repeat-Until-True which is basically an invert of the While-True thereby we will not be classifying this as a separate behavior.
This behavior is coded as illustrated below.
BW5
BW6/CE
To do this in Flogo, we use the Loop configuration of the activity. Most of the activities inside Flogo support looping in this manner. Inside this configuration, you will set the Type to “Repeat while true” and provide the condition to repeat execution of the specific activities.
One thing to note though is the evaluation of the condition and the index of the iteration.
In BusinessWorks, the evaluation happens at the start of the group and the index starts at 1. This means that in order to execute 3 times, my condition will need to evaluate the index to be less than or equal to 3.
In Flogo, the evaluation happens at the end of the activity. Additionally, the index starts at 0. This means that in order to replicate the exact same behavior as the example in BW, we would need to evaluate the condition to be less than 2 as shown below and compensate for the logging of the “Iteration: <<number>>” message by adding 1 to the index as shown below. Other than this, the behavior of the BW application is completely replicated in the Flogo application.
Flogo
Group-While-True With Multiple Activities
One might ask that if the loop is within the Activity in Flogo, how do we then replicate the behavior of a loop that contains multiple activities in BusinessWorks. For this scenario, we use the below. You can see that we have two activities inside the group that is iterating. Each activity is executed once before the loop repeats.
BW5
BW6/CE
To accomplish this in Flogo, we use a subflow. A subflow is similar to a subprocess in BusinessWorks. Within this subflow, you put all the activities you want to iterate in sequence.
Then we have a main flow which uses the Start A Subflow activity to execute the subflow. We then configure the iteration in the loop subtab like the previous Flogo example taking into account the same adjustment needed based on the conditional evaluation and index in Flogo. Any data needed for the subflow is passed in during this call.
Group-Iterate
Another type of iteration typically used in BusinessWorks is the iteration based on data elements. For this example, we have a repeating schema which houses customer names. We would want to iterate through the customers in the group and print out each name. The implementation of this for BusinessWorks is shown below.
BW5
BW6/CE
To do this in Flogo is relatively simple. We also have a mapper which we pre-create a repeating schema just like BusinessWorks.
We also use the Loop configuration of the activity to achieve this iteration. To iterate on the repeating data element, select the type as Iterate and provide the repeating element as the iterator element. Just like in BusinessWorks, you will be able to drag this from the “Available Data” section into the configuration text box. In the screenshot below, you can see that element is the $activity[RepeatingSchema].output.root dragged from Available data > RepeatingSchema > output > root. Notice the root element has an “Arr” icon which indicates an array repeating element.
We can then map the iterator data value from the $iteration object in the Available data section for use in the iteration.
Group-Repeat-On-Error-Until-True
There is another common iteration activity called Repeat-On-Error-Until-True. What this does is if there is an exception in the group, it will repeat execution of activities in the group up to a certain number of times as long as the exception continues. After the retry is exhausted, it will then propagate the exception upwards to the parent.
BW5
BW6/CE
Flogo approached this a little differently compared to BusinessWorks. It does not provide a repeat on error for all the activities. This is because when an exception happens to an activity, not all exceptions are correctable but re-executing it. So, this function is only provided to activities that could be potentially corrected by re-execution.
One such activity is the InvokeRESTService. In this example, a fake URL is used and a timeout for this invocation is set to 1000 milliseconds. Then we configure the Retry On Error with a count of 3 and an wait interval of 5000 milliseconds.
In running this, we observed that the activity retried itself 3 times on failure. After the third failure, it propagates the exception to the parent just like BusinessWorks does.
For-Each-Mapping
The For-Each-Mapping iteration happens within the Mapper in BusinessWorks. This facilitates mapping of complex schemas from one to another.
BW5
BW6/CE
To achieve this in Flogo, we can use a similar method within the Flogo Mapper to iterate through the repeating element and mapping the repeat element over to the new schema.
All three projects coded in BW 5.15.1, BWCE 2.9.1 and Flogo 2.24.0 using the Visual Studio Code Extension are provided below for your reference.
BW_5_15_1-F4BWDev-Iteration.zip BWCE_2_9_1-F4BWDev-Iteration.zip Iteration.flogo
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now