Mule 3.9: Using Timer Interceptor [Snippet]
Let's take a look at how to calculate the flow execution time without using any custom code or logic in Mule.
Join the DZone community and get the full member experience.
Join For FreeIn this article, I will show you how to calculate the flow execution time without using any custom code or logic in Mule. Using Timer Interceptor, we are able to see the execution time of a private flow in Mule logs. This is very helpful when it comes to checking the performance of your flows, especially when doing performance testing.
<timer-interceptor doc:name="Timer Interceptor"/>
Using the Timer-Interceptor:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<flow name="dzone-mule-appsFlow">
<poll doc:name="Runs every 10 seconds">
<fixed-frequency-scheduler frequency="10000"/>
<logger level="INFO" doc:name="Logger" message="#[message.rootId] - Start Of Process"/>
</poll>
<timer-interceptor doc:name="Timer Interceptor"/>
<flow-ref name="sf-main-logic" doc:name="sf-main-logic"/>
<logger message="#[message.rootId] - End Of Process" level="INFO" doc:name="Logger"/>
</flow>
<sub-flow name="sf-main-logic">
<scripting:transformer doc:name="Groovy Sleep(10000)">
<scripting:script engine="Groovy"><![CDATA[sleep(5000);]]></scripting:script>
</scripting:transformer>
</sub-flow>
</mule>
For more details creating custom interceptor, check this out: https://docs.mulesoft.com/mule-user-guide/v/3.9/using-interceptors#timer-interceptor
Testing:
The Timer Interceptor logged the flow name and the captured process duration.
Thanks for reading. Please let me know if you have any questions in the comments section.
Opinions expressed by DZone contributors are their own.
Comments