Parallel shape in Logic A

Check out the latest Article
https://social.technet.microsoft.com/wiki/contents/articles/37620.parallel-processing-in-logic-app.aspx

Introduction

In this article I would like to explain batch processing using parallel shape in Logic App. Parallel Processing in Logic app is a mechanism by which two or more different actions can take place concurrently but independently.

Scenario

Consider an example, We are going to create an Logic App API which accepts one parameter in URL and returns 5 records per call. The records will be selected based on the “Page Number” parameter that we pass in URL.

  1. If we pass 1, first 5 records of data will be returned.
  2. If the “Page Number is 2 then it would be second set of Records, that is 6-10 records.

Logic App gets those 5 records by calling the below REST API 5 times based on the “Page Number” parameter and returns the cumulative result.

GetPosts() Rest Service

4

The behavior of the REST Service is,

7.PNG

Parallel Shape

Since there is no ordering is important we could call the Services parallel using parallel shape. This cant be achieved using Logic App Designer and we need to tweak the code in code window. If we need to add any 2 shapes under parallel shape then we need to add previous shapes id into runafter() element.

5.PNG

In this example, I would like to add “Increment_PostNumberBy1” and “Increment_PostNumberBy1” shapes into Parallel shape, so I added the previous shape’s id “Intialize_variable” into runafter() that makes the designer as below.

20.PNG

Detailed Implementation

We have one http GET receive shape that accepts one URL parameter called “pageNumber”, based on this page number we need to return the results

15.PNG

Assign the “pageNumber” in to a integer variable called “PostNumber”, use int() function to convert “pageNumber” into Integer and use mul() to multiply it with 5.

1.JPG

Create a parallel shape that has 5 branches and create the REST calls to the mentioned API to get respective posts.

Increment “PostNumber” by 1

21.png

Create a REST API Request using “PostNumber” variable.

22.png

Posts are in Latin language so we call Google’s translate API service to convert it in English

23.JPG

Accumulate the result and from a JSON response and return to the caller.

24.JPG

The overall workflow would be as follows,

17.PNG

In PostMan, the API call would be,

25.JPG

Conclusion

I have used PostMan for testing and Using parallel shape it took almost 5 seconds average to process it.

27.JPG

But if we change the workflow to Sequential, the average came down to 3 seconds

28.JPG

Our Sequential flow would look like below,

30.JPG

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

WordPress.com.

Up ↑

%d bloggers like this: