2017-05-04 62 views
0

我目前正在嘗試檢查騾流的時間,如果有幫助,我的騾子ESB版本是3.8.3。查找過程騾流量所花費的時間

我使用<custom-inteceptor>這個任務也因此造就延伸AbstractEnvelopeInterceptor類,代碼如下一個Java類,

@Override 
public MuleEvent last(MuleEvent event, ProcessingTime time, long startTime, boolean exceptionWasThrown) 
     throws MuleException 
{ 

    long endTime = System.currentTimeMillis(); 

    if(logger.isInfoEnabled()) 
    { 
    logger.info("+++++++++++++++++++++++++++++++++++++++++++++" 
      +" Flow : "+event.getFlowConstruct().getName() 
      + " Started @ " +startTime+" Ended @ "+endTime 
      +" Processing Time : "+(endTime - startTime)+" ms " 
      + "+++++++++++++++++++++++++++++++++++++++++++++"); 

    } 
    return event; 
} 

我得到一個java.lang.NullPointerException當我嘗試獲取即在流動名event.getFlowConstruct().getName()這是顯示如上

此外,即使我刪除它只是檢查流程所花費的時間,它給出0毫秒作爲輸出,也是我的批處理過程不會執行後,它被打印在consol

我試圖把在開始<custom-inteceptor>以及流的結束,但仍然給我0毫秒出於某種原因

的流程如下,

<flow name="batch-sample-1Flow"> 
    <http:listener config-ref="HTTP_Listener_Configuration" path="/bs" doc:name="HTTP"/> 
    <custom-interceptor class="com.utility.CustomTimeInteceptor"/> 
    <batch:execute name="batch-sample-1Batch" doc:name="batch-sample-1Batch"/> 

</flow> 

是的,我調用在調用批處理之前放置<custom-inteceptor>時不執行的批處理過程。

如果還有其他方法來監視批處理過程,我們將不勝感激。

編輯:

我擴展AbstractEnvelopeInterceptor類是一些有關使用它嗎?

回答

0

只需使用類AbstractInterceptingMessageProcessor攔截接口來創建自定義攔截器...,做編碼這樣創建自定義攔截

private static Log logger = LogFactory.getLog(TimerInterceptor.class); 

public MuleEvent process(MuleEvent event) throws MuleException { 
long startTime = System.currentTimeMillis(); 
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 
Date stdate = new Date(); 
String start = dateFormat.format(stdate); 
System.out.println(start); 

MuleEvent resultEvent = processNext(event); 

Date enddate = new Date(); 
String end = dateFormat.format(enddate); 

if (logger.isInfoEnabled()) { 

long executionTime = System.currentTimeMillis() - startTime; 
     logger.info("Custom Timer : "+resultEvent.getFlowConstruct().getName() + " Start at "+start+" and end at "+end +" it took " + executionTime + "ms to process event ["  + resultEvent.getId() + "]"); 
} 
return resultEvent; 
}