毛鸡儿的小jian猪

自律中~

Jmeter——Jmeter测试dubbo接口
一、安装Zookeeper环境
2、启动:
二、搭建Dubbo提供者
1、新建maven项目
2、新建接口类,DemoService
public interface DemoService {

	String getStr(String first,String second);
}
3、新建类DemoServiceImpl实现接口DemoService
public class DemoServiceImpl implements DemoService{

	@Override
	public String getStr(String first, String second) {
		return first+" ___" +second+"___";
	}
}
4、新建log4j配置文件
5、新建xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans.xsd  
        http://code.alibabatech.com/schema/dubbo  
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd  
        ">
	<bean id="demoService" class="com.wx.provider.impl.DemoServiceImpl" />
	<dubbo:application name="wuxi-dubbo-provider" />
	<dubbo:registry address="zookeeper://localhost:2181" />
	<!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="20880" /> 
	<!-- 声明需要暴露的服务接口 -->
	<dubbo:service interface="com.wx.provider.DemoService"
		ref="demoService" />
</beans>
6、pom文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.wuxi</groupId>
	<artifactId>Wuxi-Dubbo-Provider</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>Wuxi-Dubbo-Provider</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		    <!-- http://mvnrepository.com/artifact/com.alibaba/dubbo -->
     <dependency>
	    <groupId>com.alibaba</groupId>
	    <artifactId>dubbo</artifactId>
	    <version>2.5.3</version>
     </dependency>
    <!-- http://mvnrepository.com/artifact/com.101tec/zkclient -->
	<dependency>
	    <groupId>com.101tec</groupId>
	    <artifactId>zkclient</artifactId>
	    <version>0.8</version>
	</dependency>
    <!-- http://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper -->
	<dependency>
	    <groupId>org.apache.zookeeper</groupId>
	    <artifactId>zookeeper</artifactId>
	    <version>3.4.8</version>
	    <!-- <type>pom</type> -->
	</dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>  
	    <groupId>org.apache.maven.plugins</groupId>  
	    <artifactId>maven-resources-plugin</artifactId>  
	    <version>2.6</version>  
	     <configuration>  
	       <encoding>utf-8</encoding>  
	     </configuration>  
      </plugin>
    </plugins>
  </build>
  
</project>
7、执行类,启动service注册到zk提供者
执行主要结果如下:表示该服务成功注册,作为服务提供者
三、搭建dubbo消费者
1、mvn install:将provider进行打包,供消费者项目调用
2、新建maven项目
添加依赖:provider包,jmeter版本的jar包,zk、dubbo等jar包
具体pom文件如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.wuxi</groupId>
  <artifactId>Wuxi-Dubbo-Customer</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Wuxi-Dubbo-Customer</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
	<!-- http://mvnrepository.com/artifact/com.alibaba/dubbo -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>dubbo</artifactId>
			<version>2.5.3</version>
		</dependency>
		<!-- http://mvnrepository.com/artifact/com.101tec/zkclient -->
		<dependency>
			<groupId>com.101tec</groupId>
			<artifactId>zkclient</artifactId>
			<version>0.8</version>
		</dependency>
		<!-- http://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper -->
		<dependency>
			<groupId>org.apache.zookeeper</groupId>
			<artifactId>zookeeper</artifactId>
			<version>3.4.8</version>
			<!-- <type>pom</type> -->
		</dependency>
		
		<dependency>
			<groupId>javabuilder</groupId>
			<artifactId>javabuilder</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/src/main/Wuxi-Dubbo-Provider-0.0.1-SNAPSHOT.jar</systemPath>
		</dependency>
	


		<!-- java jmeter依赖jar包 -->
		<dependency>
			<groupId>org.apache.jmeter</groupId>
			<artifactId>ApacheJMeter_core</artifactId>
			<version>3.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.jmeter</groupId>
			<artifactId>ApacheJMeter_java</artifactId>
			<version>3.2</version>
		</dependency>





	</dependencies>
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.2</version>
				<configuration>
					<version>3.1</version>
					<failOnMissingWebXml>false</failOnMissingWebXml>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<encoding>utf-8</encoding>
				</configuration>
			</plugin>

			<!--打包生成依赖的jar包 -->

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<mainClass>com.wx.jmeter.dubbo.JmeterDubboLoadTest</mainClass>
						</manifest>
						<manifestEntries>
							<Class-Path>.</Class-Path>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy</id>
						<phase>install</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>
								target/lib
							</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>


		</plugins>
	</build>
</project>

3、添加customer.xml:zk地址,rpc接口
4、添加log4j配置
5、jmeter测试类,跟测试java接口唯一不同的是方法的引用,其他测试方法一样
      //方法的引用 
	private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
			new String[] { "customer.xml" });
        
	DemoService demoService = (DemoService) context.getBean("demoService");
	String c = demoService.getStr(a, b);
可以在main里进行简单调试

四、jar包添加到jmeter/lib/ext目录下
1、mvn install ,打包:dubbo接口及依赖的jar包
2、依赖的jar包在target/lib下
3、所有jar包copy到jmeter/lib/ext目录下
4、打开jemter会报错,重复的jar
删除ext对应的jar包即可
再次打开成功

五、jmeter进行测试
运行成功:


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wx19900503/article/details/80316869
所属专栏: Jmeter
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Jmeter——Jmeter测试dubbo接口

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭