SubFlow Scope in Mule
Subflows, which always run synchronously, inherit both the processing strategy and exception strategy of the flow that triggered its execution. Compared to keeping all message processing activity contained within a single flow, using a subflow to complete some message processing activities offers a few advantages:
A subflow can isolate logical processing blocks, making the graphical view more intuitive and the underlying XML code much easier to read.
Subflows are ideally suited for code reuse, so you can write a particular block of code once, then reference the same subflow repeatedly from within the same application. The diagram below offers an example of a subflow that is executed twice by different flow reference components in the same flow.
SubFlow example :
Here flow reference is used to connect main flow with subflow.
flow reference configuration :
We need to give name of subflow in it.
URL : http://localhost:8085/api/subflow
Method : GET
When you hit the URL :
Output :
XML project code :
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8085" basePath="/api" doc:name="HTTP Listener Configuration"/>
<flow name="test_sub-flowFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/subflow" doc:name="HTTP"/>
<logger message="---------In Main Flow-----------" level="INFO" doc:name="Logger"/>
<flow-ref name="test_sub-flowSub_Flow" doc:name="Flow Reference"/>
<logger message="-----------Again in Main Flow-------------" level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="test_sub-flowSub_Flow">
<logger message="-----------In Sub Flow-------------" level="INFO" doc:name="Logger"/>
</sub-flow>
</mule>
No comments:
Post a Comment