Posted on Leave a comment

Until Successful

UNTIL SUCCESSFUL

 

The Until Successful scope processes the components within it until they succeed or exhaust the maximum number of retries.

Until Successful runs synchronously.

Until Successful component

Configure of Until-Successful-

Max Retries:- Specifies the maximum number of retries that are attempted

Milliseconds Between Retries:- Specifies the minimum interval between   two attempts to process, in milliseconds, Default value is 1 Min

 

Step1:-

Wrap the HTTP Requester inside Until Successful

Step2:-

We have configured the Retries Interval as 20 ms (You can configure as per the requirement) and max Retries is 3.

 

Step3:-

In case of success scenario ,

there will not be any error received from Rest API(http status will be 200) and success response will be retrieved.

In case of failure scenario

Until Successful retries the failed task until all configured retries are exhausted and if final retry does not succeed . until successful produces an error.

if a retry succeeds .the scope proceeds to next component

Posted on Leave a comment

Round-Robin

Round Robin

This router iterates through all the routes in the router component in a specific order but it only routes to one of the routes each time it is executed. For example, it keeps track of the last route it selected for execution and will not execute the same route again consecutively.

Basically, this router works in a circular manner and whichever route executes first will not be executed in the next execution till all the other routes are executed at least once.

Round Robin component

Use Case :-

Below is the simple demo where the “first-logger” route will execute first and in the immediate next iteration,”second-logger” will be executed and this sequence will continue.

 

First-logger is executing

Second-logger is executing:-

 

 

Posted on Leave a comment

Scatter-Gather

Scatter-Gather

“Scatter-Gather sends the requested data to multiple routes concurrently“.

It waits for all the routes to complete the execution and then aggregates the response from each route and forms a Single output message and output will be “application/java” format.

 

 

Use Case :-

 

Response:-

You can see in console of studio,

In above picture, uber01 and uber02 both are threads. and “Scather-gatherapiFlow/processors/0/route/0/processors/0” is first route path and “Scather-gatherapiFlow/processors/0/route/1/processors/0” is second route path.

 

NotePoint1:-

“The maximum time taken by Scatter-Gather to complete the execution is the max time taken by any route. For instance, if route-1 takes 5 secs and route-2 takes 10 secs then Scatter-Gather will take 10 secs to complete the execution.”

NotePoint2:-

“one of the routes fails, then the entire Scatter-Gather process fails.”

 

Working-flow

 

1-first route will be trigger

2-Second flow will be trigger

In debug mode, We can see working of processor.

 

Posted on Leave a comment

Choice Router

Choice

Choice Router works on the evaluation of the expression i.e., True or False. The Route for which the expression evaluates to be True, that route is executed.

It executes routes sequentially i.e. if for both route-1 and route-2 condition expression evaluates to be true, it will execute only route-1 because of its sequential nature and will not execute route-2.

The expression cannot be kept as blank and there is a default block that executes if none of the expressions evaluates to True.

 

Use Case 1:-

in above picture,

we set the variable “Id” and  value is “payload.empId”.

We are sending empId in body section.

Response:-

 

Use Case 2:-

If “empId” is null , then this comes in the input then the Default route will be triggered.

We are sending Null empId in body.

Response:-

 

Posted on Leave a comment

Flow Control in Mule 4

We will see four different Flow control components provided in Mule. We will also cover various use cases.

In Mule, Flow Controls , you Route your input Mule Event into one or more  separate flows based on the Flow control components you use.

Type of Flow Control component:-

1-Choice

2-Scatter-Gather

3-Round-Robin

4-First Successful

 

The detailed explanation on each topics is in next section.

Posted on Leave a comment

Define Responses in RAML

We will get responses from api or external service . there are two type of responses , we will get .

positive response ->success case

Negative response ->failure case

we have to mention all responses in Raml file.

 

Step1:-

Create a specific folder for “Response”

Step2:-

Create files like 200.json,401.json,400.json,500.json

Step3:-

We will refer these file into rootfile(main file) and will use “!include” keyword.

Step4:-

validate your responses

 

Posted on Leave a comment

USAGE OF LIBRARY FRAGMENT

We will explain the usage of library fragment in raml. Library is one of the Raml Fragments. Main advantage of the raml Library is that is can defined multiple types and that can be referred from RAML file.

Step1:-

Log in to Anypoint platform

Step2:-

Click on design center and click on Create Fragments

Step3:-

Provide the name for new fragment

Step4:-

Update the RAML with below information

Define the Individual DataType which is included as part of library

Notepoint:-

Once you create the Library as a fragment you can publish it on exchange to make it reusable across organization, else you can also use this inside individual raml specification in that case you can first create a RAML specification and add the file as a library .

 

Step5:-

we use  uses: “ to include the library and also refer this from exchange, in case of library it is not required to use “!include” to include the library.

 

 

 

Posted on Leave a comment

GENERATE FLOWS FROM RAML

In this tutorial, “we will Generate Flows From RAML Using Manage Dependency, This is one of the easiest way to generate the flow from RAML, in that case raml will be referred from Anypoint Exchange directly and a dependency will be added in POM.xml”

Step1:-

Create a sample RAML in design center

Step2:-

Created the endpoint “/search/{id}”  with get method and here id is uriparams and queryParameters is defined in Raml .

Step3:-

Publish the API on Exchange, see below sampleAPI is published on exchange with version 1.0.0

and

Step4:-

Create a sample project in anypoint studio

Step5:-

after creating project.

Step6:-

Right Click on project and click on manage dependency-> Click on Manage API

Step7:-

New Window Open-> Click on + Sign and click on From Exchange

Step8:-

A new search window will open to search modules/api from exchange

Search sampleAPI and click on Finish

Step9:-

A new window will open with API name and version -> Click on Apply

after that ,When we click on apply it will ask for scaffold the API, click on Yes

 

Step10:-

It will give the success message, click on Apply and Close

We can see the scaffolding complete successfully and flows are generated as shown below and sampleapi.xml file generated

Step11:-

Project deployed successfully

Posted on Leave a comment

IMPORT FRAGMENTS IN RAML

In this tutorial, we will demonstrate how can we include fragments in raml api specification.

Step1:-

In “API SPECIFICATION“, Define how to api will behave and how it communicates with other system & APIs.

Create new API specification

Step2:-

Provide the name of New Api Specifiation

 

Step3:-

Basic structure is ready like shown below

Step4:-

Click on add dependency using + sign

Step5:-

Select the fragments created in last tutorial

 

Step6:-

You can see fragments are added as exchange_modules and you can use any fragment in RAML