Jmeter calls Dubbo interface

Keywords: Dubbo Apache Spring xml

Jmeter test Dubbo interface


This article introduces two ways to use jmeter to test dubbo interface

  • Call through the way of jmeter secondary development (jar) (recommended, with requirements for coding ability)
  • Call through JMeter plugins Dubbo

Call through jmeter secondary development (jar)

Millet: testservice addedit() method of target service

Resource allocation

//Introduce related resources under project lib file
 1. The dependent resources required by TestService: TestService.jar
 2.Jmeter dependent jars: jorphan.jar, ApacheJMeter_java.jar, ApacheJMeter_core.jar
 3.dubbo resource: dubbo.xsd

//Resource path
 //1.jorphan.jar (jmeter/lib for main debugging execution)
// 2.ApacheJMeter_java.jar,ApacheJMeter_core.jar (jmeter/lib/ext/)
//3.dubbo.xsd can download Dubbo resources directly through pom, and copy a dubbo.xsd from Dubbo corresponding to Maven warehouse 

  • Create a new maven project and add the following dependencies in pom.xml configuration: Dubbo, Spring
  • You also need to add the dependent test service corresponding to the test service
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

        <!-- dubbo -->
        <!-- spring test -->
        <!-- Test Service -->

  • spring configuration of Dubbo service consumers: create consumer.xml configuration under the resources directory (consumers)
For the configuration content of consumer.xml, please refer to the consumer configuration file of TestService
 (you can find the corresponding consumer profile from the deployment path of the corresponding service in the test environment, such as dubbo_client.xml)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
       xmlns:xsi="" xmlns:dubbo=""

    <description>Dubbo Consumer To configure</description>
    <!--  id The name of the interface can be used by@Resource Annotation instantiation.
          interface Is the full path to the class of the referenced interface.
          registry For the address of the warehouse id
          check by spring Check service availability at initialization
    <dubbo:application name="Test-service" owner="hank"/>
    <dubbo:consumer timeout="5000" check="false" lazy="true" retries="0"/>
    <dubbo:registry id="regTest" address="zookeeper://"/>
    <dubbo:reference id="TestService" interface="com.user.test.service.TestService" registry="regTest" check="false" version="2.0.0"/>

  • Test class writing
package com.hank.api;

import com.test.TestServicePlayCriteria;
import com.test.service.TestService;
import com.test.params.Empty;
import com.test.params.Result;
import org.apache.jmeter.samplers.SampleResult;
import org.springframework.context.ApplicationContext;

 * Description
 * @Author Hank
 * @Date Created in 2019-12-30 15:53
 * Jmeter The statistics time needs to be added, otherwise, when calling from jmeter, the response time that does not correspond to the request cannot be counted
public class ApiDubbo extends AbstractJavaSamplerClient{
    private static ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-dubbo-consumer.xml");
    private static TestService testService;
    private static long start = 0;
    private static long end = 0;

    public void setupTest(JavaSamplerContext arg0){
        start = System.currentTimeMillis();
    public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
        SampleResult sr = new SampleResult();
        sr.setSamplerData("Dubbo Api test");
        sr.sampleStart();// jmeter starts counting response time tags

        long userId = 505009;
        TestServicePlayCriteria testServicePlayCriteria = new TestServicePlayCriteria();
        Result<Empty> result = testService.addOrEdit(TestServicePlayCriteria);
        if(result.getCode().equals("00000")){  // Interface call result judgment
            sr.setSuccessful(true); //Setting jmeter return status succeeded: true
            sr.setSuccessful(false);  //Failed to set jmeter return status: false
        sr.setSamplerData(result.getCode());  // Set jmeter request to return display content
        return sr;

    public void teardownTest(JavaSamplerContext arg0) {
        end = System.currentTimeMillis();
        // Overall time consuming
        System.err.println("cost time:" + (end - start) + "Millisecond");

  • Local debugging
package com.hank.api;

import org.apache.jmeter.config.Arguments;

 * Description
 * @Author Hank
 * @Date Created in 2019-12-31 17:18
public class TestMain {
    private static JavaSamplerContext ar = new JavaSamplerContext(new Arguments());
    public static void main(String args[]){

    public static void testApiDubbo(){
        ApiDubbo apiDubbo = new ApiDubbo();


  • Local debugging results
  • Package jar (after local debugging is ok, type jar and put it in jmeter/lib/ext /)
//Packing process
// The jar storage path is under the default current project out / artifact /
1.File -> Project Structure -> Artifats -> add Library file
2.Build -> Build Artifats -> Builds

  • jmeter add the jar package you typed before and restart jmeter
  • Call result

The above is called through the way of jmeter secondary development (jar)

Called through JMeter plugins Dubbo

// Jmeter itself does not support Dubbo interface calls. You need to download a third-party plug-in to support 

// Download jmeter-plugins-dubbo-1.3.8-jar-with-dependencies.jar place jmeter/lib/ext / restart JMeter

// Additional dependent resources need to be added:


// Matters needing attention
1.When used zk,address Fill zk Address (used by cluster address","Separation),Use dubbo Direct connection, address Fill in direct connection address and service port
2.timeout: Service method call timeout(Millisecond)
3.version: Service version, consistent with the service provider's version
4.retries: Retry times of remote service call, excluding the first call, please set to0
5.cluster: Cluster mode, optional: failover/failfast/failsafe/failback/forking Service grouping. When an interface has multiple implementations, it can be distinguished by grouping. It must be consistent with the service provider
7.Interface needs to fill in full type name, including package name
8.Parameter supports any type. The wrapper class can directly use java.lang The following packaging classes are used for small types:int,float,shot,double,long,byte,boolean,char,The custom class uses the class full name.
9.Parameter value, basic packing class and basic subtype directly use value, for example:intby1booleanbytrueClass and List perhaps Map Such use json Format data.

  • Jmerter operation interface
Published 17 original articles, won praise 3, visited 6898
Private letter follow

Posted by magnetica on Tue, 14 Jan 2020 20:12:48 -0800