创建spring-boot
winddows 安装 zookeeper3.4.14 并启动
父项目用的boot创建的时候添加web依赖,其他用的是maven
父项目pom
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>common-api</module>
<module>server-provider</module>
<module>server-consumer</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cjl</groupId>
<artifactId>08-dubbo-boot-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>08-dubbo-boot-parent</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.8</version>
</dependency>
<!-- 注意包是com.alibaba.spring-->
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.5</version>
<exclusions>
<exclusion>
<artifactId>org.apache.dubbo</artifactId>
<groupId>dubbo</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.4.1</version>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--<dependency>-->
<!--<groupId>com.alibaba.boot</groupId>-->
<!--<artifactId>dubbo-spring-boot-starter</artifactId>-->
<!--<version>0.2.0</version>-->
<!--</dependency>-->
<!-- zookeeper -->
<!--<dependency>-->
<!--<groupId>org.apache.zookeeper</groupId>-->
<!--<artifactId>zookeeper</artifactId>-->
<!--<version>3.4.8</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.101tec</groupId>-->
<!--<artifactId>zkclient</artifactId>-->
<!--<version>0.10</version>-->
<!--</dependency>-->
</dependencies>
</project>
commo-api
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>08-dubbo-boot-parent</artifactId>
<groupId>com.cjl</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.cjl</groupId>
<artifactId>common-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
server-provider
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.cjl</groupId>
<artifactId>08-dubbo-boot-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.cjl.dubbo</groupId>
<artifactId>server-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>server-provider</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.cjl</groupId>
<artifactId>common-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
common 接口,实体类
server-provider
接口实现类
接口实现类
启动类
配置文件
server:
port: 9001
dubbo:
application:
# 服务名称,保持唯一
name: server-provider
# zookeeper地址,用于向其注册服务
registry:
protocal: zookeeper
address: zookeeper://127.0.0.1:2181
protocol:
name: dubbo
port: 20882
metadata-report:
address: zookeeper://127.0.0.1:2181
config-center:
address: zookeeper://127.0.0.1:2181
运行启动类,看到这个就成了
使用父项目打包,把server-provider的jar包放到jmeter 的 lib/ext目录下
把jmeter的dubbo插件也放到 扩展目录下
启动jmeter
添加 dubbo取样器
- 添加注册中心的类型、地址
- 点击那个Get按钮从注册中心获取服务列表,填写接口入参
总结:主要是依赖难搞,百度了一大圈,dubbo 2.7 版本变化也大 。
jmeter调用的原理,相当于编写一个消费者,也可以用代码编写消费者,使用@RestController对外提供接口,jmeter就可以通过http调用消费者,达到调用dubbo接口的效果
标签:dubbo,--,spring,boot,server,org,jmeter,2.7 From: https://www.cnblogs.com/age28/p/17367506.html