Calculating Processing time for a Mule flow by using Interceptors

前端 未结 3 1508
抹茶落季
抹茶落季 2021-01-23 10:33

I want to calculate the execution time which my mule flow takes for execution,so I have used interceptor for it, here is my interceptor code

    class CustomLogg         


        
3条回答
  •  孤街浪徒
    2021-01-23 10:58

    You can do it by following 2 ways :-

    1) By using a timer interceptor :-

    
    

    Put this at the end of your flow

    2) Use custom interceptor to create your own timer interceptor :-

    Use this at the end of the flow :-

    
    

    and com.customInterceptor.TimerInterceptor class :-

    import org.mule.api.MuleEvent;
    import org.mule.api.MuleException;
    import org.mule.api.interceptor.Interceptor;
    import org.mule.processor.AbstractInterceptingMessageProcessor;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    /**
     * TimerInterceptor simply times and displays the time taken to
     * process an event.
     */
    public class TimerInterceptor extends AbstractInterceptingMessageProcessor
            implements Interceptor {
        /**
         * logger used by this class
         */
        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;
        }
    }
    

提交回复
热议问题