二、dubbo-consumer
文章插图
1、UserController
@RestControllerpublic class UserController { @Reference // 引用dubbo服务器提供服务器接口 private UserService userService; @GetMapping("/login") public UserInfo login(UserInfo userInfo) { return userService.login(userInfo); }}2、DubboConsumerApplication
@SpringBootApplication@EnableDubboConfiguration // 启用dubbo自动配置public class DubboConsumerApplication { public static void main(String[] args) { SpringApplication.run(DubboConsumerApplication.class, args); }}3、pom.xml
<?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"> <modelVersion>4.0.0</modelVersion> <groupId>com.boot.dubbo.demo</groupId> <artifactId>dubbo-consumer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>dubbo-consumer</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--依赖dubbo-provider服务提供者--> <dependency> <groupId>com.boot.dubbo.demo</groupId> <artifactId>dubbo-provider</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <!--Dubbo依赖--> <dependency> <groupId>com.alibaba.spring.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency> <!--Zookeeper客户端--> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.10</version> </dependency> <!--Zookeeper依赖,排除log4j避免依赖冲突--> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.10</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>4、application.yml
spring: dubbo: application: name: dubbo-consumer protocol: name: dubbo port: 20880 registry: address: zookeeper://127.0.0.1:2181server: port: 8081三、Zookeeper安装配置「链接」
「链接」
【Dubbo+Zookeeper的RPC远程调用框架demo】「链接」
四、项目启动
文章插图
五、查看Zookeeper服务注册情况
文章插图
六、通过浏览器发送请求(dubbo-provider的服务注册到Zookeeper上,dubbo-consumer消费者可以调用注册的服务) 。
到此,rpc远程调用服务通了!感兴趣的话可以去学习下 。
推荐阅读
- 谷歌地图诡异地点坐标 谷歌地图恐怖的地理坐标
- 淘宝店铺交保证金与不交保证金的区别 现在淘宝开店不需要交保证金了吗
- H3C交换机如何配置?如何一步步的创建vlan?
- 官方 一些QQ相关的免费API接口
- 参宿三爆炸 参宿四如果真的爆炸,多久会影响地球
- 彻底理解python中的yield函数
- VLAN工作原理之TRUNK:Native Vlan收到不带VLAN的Frame如何处理
- c店和天猫店的区别 c店是淘宝还是天猫
- 网线对网速的影响有多大 以及如何选择网线
- 西湖龙井玻璃杯沏泡法的步骤是怎样的