简体   繁体   中英

WSO2 ESB How to measure the response time of call or send mediator

是否有任何官方支持的方法来显示从WSO2 ESB发出呼叫或发送调解器的确切响应时间?

You can use the inbuilt Synapse Message Context Property and do this easily. The Synapse Message Context Property can retrieve the current time in milliseconds and you can set this value to a property at any desired point of the flow and access it whenever you need it.

You can set the property as shown below.

<property name="TIME" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"/>
...
<log>
 <property name="Time : " expression="get-property('TIME')"/>
</log>
...

Let's say you've logged the starting time and the end time as two properties named ' TIME_START ' and ' TIME_END ', you can take the time difference using a script mediator as shown in the example below.

<script language="js">
 var time1 = mc.getProperty("TIME_START");
 var time2 = mc.getProperty("TIME_END");
 var timeDifference = time2 - time1;
 print("Response Time :  " + timeDifference + " ms ");
 mc.setProperty("RESPONSE_TIME", timeDifference);
</script>

The following is a sample proxy service with the response time calculation bit.

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="SampleTimeProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="TIME_START"
                   expression="get-property('SYSTEM_TIME')"
                   scope="default"
                   type="LONG"/>
      </inSequence>
      <outSequence>
         <send/>
         <property name="TIME_END"
                   expression="get-property('SYSTEM_TIME')"
                   scope="default"
                   type="LONG"/>
         <script language="js">
              var time1 = mc.getProperty("TIME_START");
              var time2 = mc.getProperty("TIME_END");
              var timeDifference = time2 - time1;
              print("--------------  " + timeDifference + " ms  -----------------");
              mc.setProperty("RESPONSE_TIME", timeDifference);
         </script>
         <log>
            <property name="Response Time in ms: " expression="get-property('RESPONSE_TIME')"/>
         </log>
      </outSequence>
      <endpoint>
         <address uri="http://localhost:8080/axis2/services/SampleService"/>
      </endpoint>
   </target>
   <publishWSDL uri="http://localhost:8080/axis2/services/SampleService?wsdl"/>
   <description/>
</proxy>

Here we are setting the response time as another property named ' RESPONSE_TIME '.

You can read more on this blog: http://sumedhask.blogspot.com/2013/10/a-simple-way-to-log-time-durations-in.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM