0

我们需要登录 WSO2ESB 的日志文件,每次调用代理实例的持续时间。例如:.... 10:10:14,736 [MessageID : xxxxxxxxx] [duration : 259 ms] ....

这意味着与 MessageID xxxxxxxx 关联的代理调用的持续时间为 259 毫秒。我不想主动统计调解员或 BAM 调解员。

有什么想法可以轻松点吗?尼古拉斯

4

1 回答 1

1

您可以使用SYSTEM_TIME属性,它是Synapse Message Context Property。使用它,您可以在消息流的所需位置获取当前时间(以毫秒为单位)并将值设置为属性。然后,您可以使用Script Mediator编写一个小脚本(Javascript 或 Ruby)来读取时间值(存储在属性中)并进行必要的计算。您可以在脚本调解器中显示结果,也可以将其设置为新的属性,以便可以将其记录在代理中。

  1. 突触消息上下文属性

    http://docs.wso2.org/display/ESB470/Synapse+Message+Context+Properties

  2. 使用脚本中介

    http://docs.wso2.org/pages/viewpage.action?pageId=26838871

  3. 日志中介

    http://docs.wso2.org/display/ESB470/Log+Mediator

以下示例可能会对您有所帮助。

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="SampleTimeProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="TIME_1"
                   expression="get-property('SYSTEM_TIME')"
                   scope="default"
                   type="LONG"/>
      </inSequence>
      <outSequence>
         <send/>
         <property name="TIME_2"
                   expression="get-property('SYSTEM_TIME')"
                   scope="default"
                   type="LONG"/>
         <script language="js">var time1 = mc.getProperty("TIME_1");
              var time2 = mc.getProperty("TIME_2");
              var timeTaken = time2 - time1;
              print("--------------  " + timeTaken + " ms  -----------------");
              mc.setProperty("RESPONSE_TIME", timeTaken);
         </script>
         <log>
            <property name="time" expression="get-property('RESPONSE_TIME')"/>
         </log>
      </outSequence>
      <endpoint>
         <address uri="http://localhost:8080/axis2/services/SimpleStockQuoteService"/>
      </endpoint>
   </target>
   <publishWSDL uri="http://localhost:8080/axis2/services/SimpleStockQuoteService?wsdl"/>
   <description/>
</proxy>
                            
于 2013-10-05T16:33:06.243 回答