@hb_mulesoftTechworld
Note: the xml example is added with : and ;
Unable touse angular brackets
Routers
==
Choice::
We need to configure at least one route,
and there will be one default route
It will execute the routes whenever the condition matches.
If two routes are configured with the same expression, only the first matched route will be executed.
Scatter gather::
We need to configure more than one route.
We can send same request/payload to multiple routes to validate and fetch the required information.
And we need to consolidate the response from all the routes.
It will throw MULE:COMPSITE_ROUTING exception, if any route is failed.
Round Robin Router::
We need to configure more than one route,
And the routes will be executed in load balancing way/parallel processing/multi-tasking, like each time the request will be sent to the immediate next route rather than the same/previously executed route.
If all the routes are completed, then the request will be routed to the first route and the process will repeat as mentioned in step2 for each subsequent request.
First Successful::
We need to configure more than one route
And whenever the expression of route/all the message processors are executed successfully in the configured route, then the response will be returned from the particular route.
If none of the routes are executed in a success state, then it will throw an exception.
1. We need to get suppliers information with the status active/inactive when we send a parameter.
If no parameter is sent we need a list of all suppliers
And also if the format=xml header is sent from the request or consumer, we need the suppliers response in xml format
otherwise, we need a response in json format.
2. For a supplier we want to get the list of items he is able to deliver.
we have two systems System B, System C where the items data is stored for the suppliers.
We need to collect all the items from both systems and send the response to System A consumer application.
{
"supplierNumber": "sup1",
"supplierName": "Tata Group",
"isActive": "Yes",
"address": "Mumbai",
"state": "Maharashtra",
"items": [
{
"itemId": "E0001",
"name": "LG Tv",
"type": "Electronics",
"supplierNum": "sup1"
}
]
}
3. System D and System E have same replicas of suppliers information.
We need to get the response from either of the systems, but each time the request needs to be routed to different system.
4. List the items information from System B or System C.
Evaluate with header source=systemB or systemC and give response.
Suppliers data set
::
[
{
"supplierNumber": "sup1",
"supplierName": "Tata Group",
"isActive": "Yes",
"address": "Mumbai",
"state": "Maharashtra"
},
{
"supplierNumber": "sup2",
"supplierName": "Saankhya",
"isActive": "Yes",
"address": "Pune",
"state": "Maharashtra"
},
{
"supplierNumber": "sup3",
"supplierName": "Human Brains Techworld",
"isActive": "Yes",
"address": "Hyderabad",
"state": "Telangana"
},
{
"supplierNumber": "sup4",
"supplierName": "Human Brains Supplychain",
"isActive": "No",
"address": "Kadapa",
"state": "Andhra Pradesh"
}
]
Suppliers XML data set
::
:suppliers;
:supplier;
:name;Tata Group:/name;
:supNumber;sup1:/supNumber;
:status;Active:/status;
:address;
:line1;Mumbai:/line1;
:state;Maharashtra:/state;
:/address;
:/supplier;
:supplier;
:name;Human Brains Supplychain:/name;
:supNumber;sup4:/supNumber;
:status;Active:/status;
:address;
:line1;Kadapa:/line1;
:state;Andhra Pradesh:/state;
:/address;
:/supplier;
:/suppliers;
Items on System B
::
{"items":
[
{
"itemId": "E0001",
"name": "LG Tv",
"type": "Electronics",
"supplierNum": "sup1"
},
{
"itemId": "I0001",
"name": "Buddha Large idol",
"type": "Idols",
"supplierNum": "sup2"
},
{
"itemId": "E0002",
"name": "Panasonic Tv",
"type": "Electronics",
"supplierNum": "sup1"
},
{
"itemId": "EL0004",
"name": "Dell lattitude",
"type": "Laptop",
"supplierNum": "sup4"
},
{
"itemId": "FC0034",
"name": "Featherlite chair",
"type": "Furnitue",
"supplierNum": "sup4"
}
]
}
System C
::
[
{
"itemId": "CE0002",
"name": "LG Tv2",
"type": "Electronics",
"supplierNum": "sup1"
},
{
"itemId": "CI0001",
"name": "Buddha small idol",
"type": "Idols",
"supplierNum": "sup2"
},
{
"itemId": "CEL0004",
"name": "HP elite book",
"type": "Laptop",
"supplierNum": "sup4"
}
]