SlideShare a Scribd company logo
1 of 13
By Anirban Sen Chowdhary
.
Here I will show you how ……
We can use a Mule component called custom-interceptor in
our flow
With this we can calculate the total amount of time
taken in our flow
So, we can take following Mule flow to demonstrate :-
So, we can use the following tag in our flow of our Mule config
to execute total time:-
<custom-interceptor
class="com.customInterceptor.TimerInterceptor" />
And our java class TimerInterceptor will be:-
public class TimerInterceptor extends AbstractInterceptingMessageProcessor
implements Interceptor {
private static Log logger = LogFactory.getLog(TimerInterceptor.class);
public MuleEvent process(MuleEvent event) throws MuleException {
long startTime = System.currentTimeMillis();
MuleEvent resultEvent = processNext(event);
if (logger.isInfoEnabled()) {
long executionTime = System.currentTimeMillis() - startTime;
logger.info("Custom Timer : "+resultEvent.getFlowConstruct().getName() + " took "
+ executionTime + "ms to process event ["
+ resultEvent.getId() + "]");
}
return resultEvent;
}
}
Now this is a complex web service that uses cache mechanism
in the flow and will fetch some data from the database
Now when we execute this flow, we will get the above in our console
Now since this flow uses a cache mechanism in the flow, if we
hit the service again , it will uses cache to fetch it’s data and it
will not hit the actual database.
So, in this case the execution time will be less as follow :-
Now when we execute this flow, we will get the above in our console
So, this is very simple, we just need to put the following
code in our flow to get the execution time:-
<custom-interceptor> with your own java class to
calculate the execution time
Hope you enjoyed the simple yet an amazing trick in Mule
Calculate Flow Execution Time in Mule with Custom Interceptor

More Related Content

What's hot

Mulesoft vm transport reference
Mulesoft vm transport referenceMulesoft vm transport reference
Mulesoft vm transport referencekumar gaurav
 
Quartz component in mule demo
Quartz component in mule demoQuartz component in mule demo
Quartz component in mule demoSudha Ch
 
Enjoy Munit with Mule
Enjoy Munit with MuleEnjoy Munit with Mule
Enjoy Munit with MuleBui Kiet
 
Junit in mule demo
Junit in mule demo Junit in mule demo
Junit in mule demo javeed_mhd
 
Message properties component in Mule
Message properties component in MuleMessage properties component in Mule
Message properties component in MuleKhan625
 
For each component in mule
For each component in muleFor each component in mule
For each component in muleRajkattamuri
 
Until successful component in mule
Until successful component in muleUntil successful component in mule
Until successful component in mulejaveed_mhd
 
Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in muleMohammed246
 
Quartz connector mule
Quartz connector   muleQuartz connector   mule
Quartz connector muleSindhu VL
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompressSon Nguyen
 
Mule requestor component
Mule requestor componentMule requestor component
Mule requestor componentSindhu VL
 

What's hot (16)

Mulesoft vm transport reference
Mulesoft vm transport referenceMulesoft vm transport reference
Mulesoft vm transport reference
 
Mule esb :Data Weave
Mule esb :Data WeaveMule esb :Data Weave
Mule esb :Data Weave
 
Quartz component in mule demo
Quartz component in mule demoQuartz component in mule demo
Quartz component in mule demo
 
Enjoy Munit with Mule
Enjoy Munit with MuleEnjoy Munit with Mule
Enjoy Munit with Mule
 
Enabling Security For ActiveMQ JMX Access
Enabling Security For ActiveMQ JMX AccessEnabling Security For ActiveMQ JMX Access
Enabling Security For ActiveMQ JMX Access
 
Junit in mule demo
Junit in mule demo Junit in mule demo
Junit in mule demo
 
Message properties component in Mule
Message properties component in MuleMessage properties component in Mule
Message properties component in Mule
 
Mule quartz
Mule quartz Mule quartz
Mule quartz
 
For each component in mule
For each component in muleFor each component in mule
For each component in mule
 
Mule with composite source
Mule with composite sourceMule with composite source
Mule with composite source
 
Until successful component in mule
Until successful component in muleUntil successful component in mule
Until successful component in mule
 
Groovy example in mule
Groovy example in muleGroovy example in mule
Groovy example in mule
 
Quartz connector mule
Quartz connector   muleQuartz connector   mule
Quartz connector mule
 
Compress and decompress
Compress and decompressCompress and decompress
Compress and decompress
 
Mule requestor component
Mule requestor componentMule requestor component
Mule requestor component
 
Encrypting/Decrypting mule
Encrypting/Decrypting  muleEncrypting/Decrypting  mule
Encrypting/Decrypting mule
 

Similar to Calculate Flow Execution Time in Mule with Custom Interceptor

Timers in Unix/Linux
Timers in Unix/LinuxTimers in Unix/Linux
Timers in Unix/Linuxgeeksrik
 
Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectosManuel Menezes de Sequeira
 
Asyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-sagaAsyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-sagaPedro Solá
 
Contiki os timer tutorial
Contiki os timer tutorialContiki os timer tutorial
Contiki os timer tutorialSalah Amean
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfmarketing413921
 
Interceptor in mule
Interceptor in muleInterceptor in mule
Interceptor in muleSon Nguyen
 
A Project Run@Timer, J2SE,
A Project Run@Timer, J2SE,A Project Run@Timer, J2SE,
A Project Run@Timer, J2SE,Swapnil Dubey
 
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at RuntimeOSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at RuntimeNETWAYS
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with KotlinRapidValue
 
Jsp session tracking
Jsp   session trackingJsp   session tracking
Jsp session trackingrvarshneyp
 
Mocking with salesforce using Munit
Mocking with salesforce using MunitMocking with salesforce using Munit
Mocking with salesforce using MunitSon Nguyen
 
倒计时优化点滴
倒计时优化点滴倒计时优化点滴
倒计时优化点滴j5726
 
Session13 J2ME Timer
Session13  J2ME TimerSession13  J2ME Timer
Session13 J2ME Timermuthusvm
 
Proposed pricing model for cloud computing
Proposed pricing model for cloud computingProposed pricing model for cloud computing
Proposed pricing model for cloud computingAdeel Javaid
 
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++   In Chapter 1- the class clockType was designed to implem.docxC++ C++ C++   In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docxCharlesCSZWhitei
 
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Yauheni Akhotnikau
 

Similar to Calculate Flow Execution Time in Mule with Custom Interceptor (20)

Timers in Unix/Linux
Timers in Unix/LinuxTimers in Unix/Linux
Timers in Unix/Linux
 
Introdução à programação orientada para aspectos
Introdução à programação orientada para aspectosIntrodução à programação orientada para aspectos
Introdução à programação orientada para aspectos
 
I os 06
I os 06I os 06
I os 06
 
Asyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-sagaAsyc flow control with javascript generators - redux-saga
Asyc flow control with javascript generators - redux-saga
 
Contiki os timer tutorial
Contiki os timer tutorialContiki os timer tutorial
Contiki os timer tutorial
 
Timer Interceptor in Mule
Timer Interceptor in MuleTimer Interceptor in Mule
Timer Interceptor in Mule
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdf
 
Interceptor in mule
Interceptor in muleInterceptor in mule
Interceptor in mule
 
A Project Run@Timer, J2SE,
A Project Run@Timer, J2SE,A Project Run@Timer, J2SE,
A Project Run@Timer, J2SE,
 
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at RuntimeOSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
OSMC 2021 | inspectIT Ocelot: Dynamic OpenTelemetry Instrumentation at Runtime
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with Kotlin
 
Jsp session tracking
Jsp   session trackingJsp   session tracking
Jsp session tracking
 
Timer control
Timer controlTimer control
Timer control
 
Mocking with salesforce using Munit
Mocking with salesforce using MunitMocking with salesforce using Munit
Mocking with salesforce using Munit
 
倒计时优化点滴
倒计时优化点滴倒计时优化点滴
倒计时优化点滴
 
Session13 J2ME Timer
Session13  J2ME TimerSession13  J2ME Timer
Session13 J2ME Timer
 
Proposed pricing model for cloud computing
Proposed pricing model for cloud computingProposed pricing model for cloud computing
Proposed pricing model for cloud computing
 
Moment.js overview
Moment.js overviewMoment.js overview
Moment.js overview
 
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++   In Chapter 1- the class clockType was designed to implem.docxC++ C++ C++   In Chapter 1- the class clockType was designed to implem.docx
C++ C++ C++ In Chapter 1- the class clockType was designed to implem.docx
 
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
 

More from Anirban Sen Chowdhary

Overview in ringcentral digital line
Overview in ringcentral digital lineOverview in ringcentral digital line
Overview in ringcentral digital lineAnirban Sen Chowdhary
 
RingCentral application development overview
RingCentral application development overviewRingCentral application development overview
RingCentral application development overviewAnirban Sen Chowdhary
 
Overview on ring central errors part 4
Overview on ring central errors part 4Overview on ring central errors part 4
Overview on ring central errors part 4Anirban Sen Chowdhary
 
Setting up your ring central sandbox in steps
Setting up your ring central sandbox in stepsSetting up your ring central sandbox in steps
Setting up your ring central sandbox in stepsAnirban Sen Chowdhary
 
Overview on ring central errors: part 2
Overview on ring central errors: part 2Overview on ring central errors: part 2
Overview on ring central errors: part 2Anirban Sen Chowdhary
 
Call recording overview ring central
Call recording overview  ring centralCall recording overview  ring central
Call recording overview ring centralAnirban Sen Chowdhary
 
Ring central engaging with amazon alexa
Ring central engaging with amazon alexaRing central engaging with amazon alexa
Ring central engaging with amazon alexaAnirban Sen Chowdhary
 
How ring central sdk changing the game
How ring central sdk changing the gameHow ring central sdk changing the game
How ring central sdk changing the gameAnirban Sen Chowdhary
 
When ring central connect salesforce
When ring central connect salesforceWhen ring central connect salesforce
When ring central connect salesforceAnirban Sen Chowdhary
 
Ring central connecting salesforce overview
Ring central connecting salesforce overviewRing central connecting salesforce overview
Ring central connecting salesforce overviewAnirban Sen Chowdhary
 
Ring central call logs overview (part 2)
Ring central call logs overview (part 2)Ring central call logs overview (part 2)
Ring central call logs overview (part 2)Anirban Sen Chowdhary
 

More from Anirban Sen Chowdhary (20)

Change the game with Game changer
Change the game with Game changerChange the game with Game changer
Change the game with Game changer
 
Ring central desktop app overview
Ring central desktop app overviewRing central desktop app overview
Ring central desktop app overview
 
Overview in ringcentral digital line
Overview in ringcentral digital lineOverview in ringcentral digital line
Overview in ringcentral digital line
 
Some basics with ring central
Some basics with ring centralSome basics with ring central
Some basics with ring central
 
Ring central and python
Ring central and pythonRing central and python
Ring central and python
 
RingCentral application development overview
RingCentral application development overviewRingCentral application development overview
RingCentral application development overview
 
Cloze connect ringcentral
Cloze connect ringcentralCloze connect ringcentral
Cloze connect ringcentral
 
Overview on ring central errors part 4
Overview on ring central errors part 4Overview on ring central errors part 4
Overview on ring central errors part 4
 
Setting up your ring central sandbox in steps
Setting up your ring central sandbox in stepsSetting up your ring central sandbox in steps
Setting up your ring central sandbox in steps
 
Overview on ring central errors: part 2
Overview on ring central errors: part 2Overview on ring central errors: part 2
Overview on ring central errors: part 2
 
Overview on ring central errors
Overview on ring central errorsOverview on ring central errors
Overview on ring central errors
 
Call recording overview ring central
Call recording overview  ring centralCall recording overview  ring central
Call recording overview ring central
 
Ring central engaging with amazon alexa
Ring central engaging with amazon alexaRing central engaging with amazon alexa
Ring central engaging with amazon alexa
 
How ring central sdk changing the game
How ring central sdk changing the gameHow ring central sdk changing the game
How ring central sdk changing the game
 
When ring central connect salesforce
When ring central connect salesforceWhen ring central connect salesforce
When ring central connect salesforce
 
Mule 4 connecting ring central
Mule 4 connecting ring centralMule 4 connecting ring central
Mule 4 connecting ring central
 
Ring central sdk
Ring central sdkRing central sdk
Ring central sdk
 
Ring central with okta
Ring central with oktaRing central with okta
Ring central with okta
 
Ring central connecting salesforce overview
Ring central connecting salesforce overviewRing central connecting salesforce overview
Ring central connecting salesforce overview
 
Ring central call logs overview (part 2)
Ring central call logs overview (part 2)Ring central call logs overview (part 2)
Ring central call logs overview (part 2)
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Calculate Flow Execution Time in Mule with Custom Interceptor

  • 1. By Anirban Sen Chowdhary
  • 2.
  • 3. .
  • 4. Here I will show you how ……
  • 5. We can use a Mule component called custom-interceptor in our flow With this we can calculate the total amount of time taken in our flow
  • 6. So, we can take following Mule flow to demonstrate :-
  • 7. So, we can use the following tag in our flow of our Mule config to execute total time:- <custom-interceptor class="com.customInterceptor.TimerInterceptor" />
  • 8. And our java class TimerInterceptor will be:- public class TimerInterceptor extends AbstractInterceptingMessageProcessor implements Interceptor { private static Log logger = LogFactory.getLog(TimerInterceptor.class); public MuleEvent process(MuleEvent event) throws MuleException { long startTime = System.currentTimeMillis(); MuleEvent resultEvent = processNext(event); if (logger.isInfoEnabled()) { long executionTime = System.currentTimeMillis() - startTime; logger.info("Custom Timer : "+resultEvent.getFlowConstruct().getName() + " took " + executionTime + "ms to process event [" + resultEvent.getId() + "]"); } return resultEvent; } }
  • 9. Now this is a complex web service that uses cache mechanism in the flow and will fetch some data from the database Now when we execute this flow, we will get the above in our console
  • 10. Now since this flow uses a cache mechanism in the flow, if we hit the service again , it will uses cache to fetch it’s data and it will not hit the actual database. So, in this case the execution time will be less as follow :- Now when we execute this flow, we will get the above in our console
  • 11. So, this is very simple, we just need to put the following code in our flow to get the execution time:- <custom-interceptor> with your own java class to calculate the execution time
  • 12. Hope you enjoyed the simple yet an amazing trick in Mule