1. 首页
  2. IT资讯

「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架

“u003Cpu003E技术博文,及时送达u003Cu002Fpu003Eu003Cimg src=”http:u002Fu002Fp3.pstatp.comu002Flargeu002Fpgc-imageu002FReU3KFWHGbeY5a” img_width=”535″ img_height=”10″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003Eu003Cpu003E作者 | 码农云帆哥u003Cu002Fpu003Eu003Cpu003E链接 | blog.csdn.netu002Fsinat_2u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-5″u003E79u003Cu002Fiu003E33301u003Cu002Fpu003Eu003Cpu003Eu003Cstrong toutiao-origin=”span” class=”highlight-text”u003E上一篇:u003Cu002Fstrongu003E从零搭建创业公司后台技术栈u003Cu002Fpu003Eu003Cpu003E这是一个基于Dubbo+Zookeeper 的 RPC 远程调用框架 demo,希望读者可以通过这篇文章大概能看懂这一个简单的框架搭建。u003Cu002Fpu003Eu003Cpu003EDemo 源码获取方式:u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-1″u003E关注u003Cu002Fiu003Eu003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-1″u003E微信u003Cu002Fiu003E公众号「Java后端 」,回复「DZ」获取u003Cu002Fpu003Eu003Cpu003EDubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和Spring框架无缝集成。u003Cu002Fpu003Eu003Cpu003EDubbo是一款高性能、轻量级的开源Java RPC框架,它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发现。u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-1″u003E微信u003Cu002Fiu003E搜索 web_resource u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-1″u003E关注u003Cu002Fiu003E获取更多推送u003Cu002Fpu003Eu003Cimg src=”http:u002Fu002Fp3.pstatp.comu002Flargeu002Fpgc-imageu002FReZhWurA0DeDV5″ img_width=”636″ img_height=”364″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003Eu003Culu003Eu003Cliu003Eu003Cpu003Eprovider:暴露服务的服务提供方u003Cu002Fpu003Eu003Cu002Fliu003Eu003Cliu003Eu003Cpu003Econsumer:调用远程服务的服务消费方u003Cu002Fpu003Eu003Cu002Fliu003Eu003Cliu003Eu003Cpu003Eregistry:服务注册于发现的注册中心u003Cu002Fpu003Eu003Cu002Fliu003Eu003Cliu003Eu003Cpu003Emonitor:统计服务调用次数和调用时间的监控中心u003Cu002Fpu003Eu003Cu002Fliu003Eu003Cliu003Eu003Cpu003Econtainer:服务运行容器u003Cu002Fpu003Eu003Cu002Fliu003Eu003Cu002Fulu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch1 toutiao-origin=”h2″u003E一、dubbo-provider(服务提供方)u003Cu002Fh1u003Eu003Cimg src=”http:u002Fu002Fp1.pstatp.comu002Flargeu002Fpgc-imageu002FReZhWvGIL8fGme” img_width=”318″ img_height=”175″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E1、Java Beanu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpu003E为什么要实现Serializable接口?当我们需要把对象的状态信息通过网络进行传输,或者需要将对象的状态信息持久化,以便将来使用时都需要把对象进行序列化。 u003Cu002Fpu003Eu003Cpu003E使用了Lombok,它能通过注解的方式,在编译时自动为属性生成构造器、getteru002Fsetter、equals、hashcode、toString方法。u003Cu002Fpu003Eu003Cpreu003Eu003Ccodeu003E@Datau003Cu002Fcodeu003Eu003Ccodeu003Epublic class UserInfo implements Serializable {u003Cu002Fcodeu003Eu003Ccodeu003E private String account;u003Cu002Fcodeu003Eu003Ccodeu003E private String password;u003Cu002Fcodeu003Eu003Ccodeu003E}u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E2、UserServiceu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpu003E服务提供方 暴露的服务,将注册到zookeeper上。u003Cu002Fpu003Eu003Cpreu003Eu003Ccodeu003Epublic interface UserService {u003Cu002Fcodeu003Eu003Ccodeu003E u002Fu002F 定义用户登录的apiu003Cu002Fcodeu003Eu003Ccodeu003E UserInfo login(UserInfo user);u003Cu002Fcodeu003Eu003Ccodeu003E}u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E3、UserServiceImplu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpu003E服务提供方暴露的服务对应的实现类。u003Cu002Fpu003Eu003Cpreu003Eu003Ccodeu003E@Componentu003Cu002Fcodeu003Eu003Ccodeu003E@Service(interfaceClass = UserService.class)u003Cu002Fcodeu003Eu003Ccodeu003Epublic class UserServiceImpl implements UserService {u003Cu002Fcodeu003Eu003Ccodeu003E public UserInfo login(UserInfo user) {u003Cu002Fcodeu003Eu003Ccodeu003E UserInfo reUser = new UserInfo;u003Cu002Fcodeu003Eu003Ccodeu003E reUser.setAccount(“登录的账号为:”+user.getAccount);u003Cu002Fcodeu003Eu003Ccodeu003E reUser.setPassword(“登录的密码为:”+user.getPassword);u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E return reUser;u003Cu002Fcodeu003Eu003Ccodeu003E }u003Cu002Fcodeu003Eu003Ccodeu003E}u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E4、DubboProviderApplicationu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpreu003Eu003Cdivu003Eu003Cpreu003Eu003Ccodeu003E@SpringBootApplicationu003Cu002Fcodeu003Eu003Ccodeu003E@EnableDubboConfiguration u002Fu002F 启用dubbo自动配置u003Cu002Fcodeu003Eu003Ccodeu003Epublic class DubboProviderApplication {u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E public static void main(String[] args) {u003Cu002Fcodeu003Eu003Ccodeu003E SpringApplication.run(DubboProviderApplication.class, args);u003Cu002Fcodeu003Eu003Ccodeu003E }u003Cu002Fcodeu003Eu003Ccodeu003E}u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cu002Fdivu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E5、pom.xmlu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpreu003Eu003Cdivu003Eu003Cpreu003Eu003Ccodeu003E<?xml version=”1.0″ encoding=”UTF-8″?>u003Cu002Fcodeu003Eu003Ccodeu003E<project xmlns=”http:u002Fu002Fmaven.apache.orgu002FPOMu002F4.0.0″ xmlns:xsi=”http:u002Fu002Fu003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-2″u003Ewwwu003Cu002Fiu003E.w3.orgu002F2001u002FXMLSchema-instance”u003Cu002Fcodeu003Eu003Ccodeu003E xsi:schemaLocation=”http:u002Fu002Fmaven.apache.orgu002FPOMu002F4.0.0 http:u002Fu002Fmaven.apache.orgu002Fxsdu002Fmaven-4.0.0.xsd”>u003Cu002Fcodeu003Eu003Ccodeu003E <modelVersion>4.0.0<u002FmodelVersion>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <groupId>com.boot.dubbo.demo<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>dubbo-provider<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>0.0.1-SNAPSHOT<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <packaging>jar<u002Fpackaging>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <name>dubbo-provider<u002Fname>u003Cu002Fcodeu003Eu003Ccodeu003E <description>Demo project for Spring Boot<u002Fdescription>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <parent>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-starter-parent<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>2.0.6.RELEASE<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <relativePathu002F> <!– lookup parent from repository –>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fparent>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <properties>u003Cu002Fcodeu003Eu003Ccodeu003E <project.build.sourceEncoding>UTF-8<u002Fproject.build.sourceEncoding>u003Cu002Fcodeu003Eu003Ccodeu003E <project.reporting.outputEncoding>UTF-8<u002Fproject.reporting.outputEncoding>u003Cu002Fcodeu003Eu003Ccodeu003E <java.version>1.8<u002Fjava.version>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fproperties>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <dependencies>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-starter-web<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–Dubbo依赖–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>com.alibaba.spring.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>dubbo-spring-boot-starter<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>2.0.0<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–自动生成getter,setter,equals,hashCode和toString等等–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.projectlombok<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>lombok<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>1.16.20<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <scope>provided<u002Fscope>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–Zookeeper客户端–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>com.101tec<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>zkclient<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>0.10<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–Zookeeper依赖,排除log4j避免依赖冲突–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.apache.zookeeper<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>zookeeper<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>3.4.10<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <exclusions>u003Cu002Fcodeu003Eu003Ccodeu003E <exclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.slf4j<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>slf4j-log4j12<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fexclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <exclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>log4j<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>log4j<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fexclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fexclusions>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-starter-test<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <scope>test<u002Fscope>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependencies>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <build>u003Cu002Fcodeu003Eu003Ccodeu003E <plugins>u003Cu002Fcodeu003Eu003Ccodeu003E <plugin>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-maven-plugin<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fplugin>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fplugins>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fbuild>u003Cu002Fcodeu003Eu003Ccodeu003E<u002Fproject>u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cu002Fdivu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E6、application.ymlu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpreu003Eu003Ccodeu003Espring:u003Cu002Fcodeu003Eu003Ccodeu003E dubbo:u003Cu002Fcodeu003Eu003Ccodeu003E application:u003Cu002Fcodeu003Eu003Ccodeu003E name: dubbo-provideru003Cu002Fcodeu003Eu003Ccodeu003E protocol:u003Cu002Fcodeu003Eu003Ccodeu003E name: dubbou003Cu002Fcodeu003Eu003Ccodeu003E port: 20880u003Cu002Fcodeu003Eu003Ccodeu003E registry:u003Cu002Fcodeu003Eu003Ccodeu003E au003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-2″u003Eddu003Cu002Fiu003Eress: zookeeper:u002Fu002F127.0.0.1:2u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-4″u003E181u003Cu002Fiu003Eu003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch1 toutiao-origin=”h2″u003E二、dubbo-consumer(服务消费方)u003Cu002Fh1u003Eu003Cimg src=”http:u002Fu002Fp9.pstatp.comu002Flargeu002Fpgc-imageu002FReZhWvR4dQiTHP” img_width=”320″ img_height=”177″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E1、UserControlleru003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpreu003Eu003Ccodeu003E@RestControlleru003Cu002Fcodeu003Eu003Ccodeu003Epublic class UserController {u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E @Reference u002Fu002F 引用dubbo服务器提供服务器接口u003Cu002Fcodeu003Eu003Ccodeu003E private UserService userService;u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E @GetMapping(“u002Flogin”)u003Cu002Fcodeu003Eu003Ccodeu003E public UserInfo login(UserInfo userInfo) {u003Cu002Fcodeu003Eu003Ccodeu003E return userService.login(userInfo);u003Cu002Fcodeu003Eu003Ccodeu003E }u003Cu002Fcodeu003Eu003Ccodeu003E}u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E2、DubboConsumerApplicationu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpreu003Eu003Ccodeu003E@SpringBootApplicationu003Cu002Fcodeu003Eu003Ccodeu003E@EnableDubboConfiguration u002Fu002F 启用dubbo自动配置u003Cu002Fcodeu003Eu003Ccodeu003Epublic class DubboConsumerApplication {u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E public static void main(String[] args) {u003Cu002Fcodeu003Eu003Ccodeu003E SpringApplication.run(DubboConsumerApplication.class, args);u003Cu002Fcodeu003Eu003Ccodeu003E }u003Cu002Fcodeu003Eu003Ccodeu003E}u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E3、pom.xmlu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpreu003Eu003Ccodeu003E<?xml version=”1.0″ encoding=”UTF-8″?>u003Cu002Fcodeu003Eu003Ccodeu003E<project xmlns=”http:u002Fu002Fmaven.apache.orgu002FPOMu002F4.0.0″ xmlns:xsi=”http:u002Fu002Fu003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-2″u003Ewwwu003Cu002Fiu003E.w3.orgu002F2001u002FXMLSchema-instance”u003Cu002Fcodeu003Eu003Ccodeu003E xsi:schemaLocation=”http:u002Fu002Fmaven.apache.orgu002FPOMu002F4.0.0 http:u002Fu002Fmaven.apache.orgu002Fxsdu002Fmaven-4.0.0.xsd”>u003Cu002Fcodeu003Eu003Ccodeu003E <modelVersion>4.0.0<u002FmodelVersion>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <groupId>com.boot.dubbo.demo<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>dubbo-consumer<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>0.0.1-SNAPSHOT<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <packaging>jar<u002Fpackaging>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <name>dubbo-consumer<u002Fname>u003Cu002Fcodeu003Eu003Ccodeu003E <description>Demo project for Spring Boot<u002Fdescription>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <parent>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-starter-parent<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>2.0.6.RELEASE<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <relativePathu002F> <!– lookup parent from repository –>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fparent>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <properties>u003Cu002Fcodeu003Eu003Ccodeu003E <project.build.sourceEncoding>UTF-8<u002Fproject.build.sourceEncoding>u003Cu002Fcodeu003Eu003Ccodeu003E <project.reporting.outputEncoding>UTF-8<u002Fproject.reporting.outputEncoding>u003Cu002Fcodeu003Eu003Ccodeu003E <java.version>1.8<u002Fjava.version>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fproperties>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <dependencies>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-starter-web<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–依赖dubbo-provider服务提供者–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>com.boot.dubbo.demo<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>dubbo-provider<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>0.0.1-SNAPSHOT<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–Dubbo依赖–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>com.alibaba.spring.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>dubbo-spring-boot-starter<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>2.0.0<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–Zookeeper客户端–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>com.101tec<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>zkclient<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>0.10<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <!–Zookeeper依赖,排除log4j避免依赖冲突–>u003Cu002Fcodeu003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.apache.zookeeper<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>zookeeper<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <version>3.4.10<u002Fversion>u003Cu002Fcodeu003Eu003Ccodeu003E <exclusions>u003Cu002Fcodeu003Eu003Ccodeu003E <exclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.slf4j<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>slf4j-log4j12<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fexclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <exclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>log4j<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>log4j<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fexclusion>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fexclusions>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <dependency>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-starter-test<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <scope>test<u002Fscope>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependency>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fdependencies>u003Cu002Fcodeu003Eu003Cbru003Eu003Ccodeu003E <build>u003Cu002Fcodeu003Eu003Ccodeu003E <plugins>u003Cu002Fcodeu003Eu003Ccodeu003E <plugin>u003Cu002Fcodeu003Eu003Ccodeu003E <groupId>org.springframework.boot<u002FgroupId>u003Cu002Fcodeu003Eu003Ccodeu003E <artifactId>spring-boot-maven-plugin<u002FartifactId>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fplugin>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fplugins>u003Cu002Fcodeu003Eu003Ccodeu003E <u002Fbuild>u003Cu002Fcodeu003Eu003Ccodeu003E<u002Fproject>u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrongu003E4、application.ymlu003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cpreu003Eu003Ccodeu003Espring:u003Cu002Fcodeu003Eu003Ccodeu003E dubbo:u003Cu002Fcodeu003Eu003Ccodeu003E application:u003Cu002Fcodeu003Eu003Ccodeu003E name: dubbo-consumeru003Cu002Fcodeu003Eu003Ccodeu003E protocol:u003Cu002Fcodeu003Eu003Ccodeu003E name: dubbou003Cu002Fcodeu003Eu003Ccodeu003E port: 20880u003Cu002Fcodeu003Eu003Ccodeu003E registry:u003Cu002Fcodeu003Eu003Ccodeu003E au003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-2″u003Eddu003Cu002Fiu003Eress: zookeeper:u002Fu002F127.0.0.1:2u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-4″u003E181u003Cu002Fiu003Eu003Cu002Fcodeu003Eu003Ccodeu003Eserver:u003Cu002Fcodeu003Eu003Ccodeu003E port: 8081u003Cu002Fcodeu003Eu003Cu002Fpreu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch1 toutiao-origin=”h2″u003E三、Zookeeper安装配置u003Cu002Fh1u003Eu003Cpu003EZookeeper是什么:u003Cu002Fpu003Eu003Cpu003Ehttps:u002Fu002Fblog.csdn.netu002Fsinat_2u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-5″u003E79u003Cu002Fiu003E33301u002Farticleu002Fdetailsu002F80101970u003Cu002Fpu003Eu003Cpu003EZookeeper的安装配置:u003Cu002Fpu003Eu003Cpu003Ehttps:u002Fu002Fblog.csdn.netu002Fsinat_2u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-5″u003E79u003Cu002Fiu003E33301u002Farticleu002Fdetailsu002F8400u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-2″u003E153u003Cu002Fiu003E0u003Cu002Fpu003Eu003Cpu003EZookeeper集群环境搭建:u003Cu002Fpu003Eu003Cpu003Ehttps:u002Fu002Fblog.csdn.netu002Fsinat_2u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-5″u003E79u003Cu002Fiu003E33301u002Farticleu002Fdetailsu002F8435u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-1″u003E140u003Cu002Fiu003E4u003Cu002Fpu003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch1 toutiao-origin=”h2″u003E四、项目启动u003Cu002Fh1u003Eu003Cimg src=”http:u002Fu002Fp1.pstatp.comu002Flargeu002Fpgc-imageu002FReZhWvg8sKXRBV” img_width=”907″ img_height=”448″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003Eu003Cpu003Eu003Cu002Fpu003Eu003Ch2 toutiao-origin=”h3″u003Eu003Cstrong toutiao-origin=”span” class=”highlight-text”u003E五、查看Zookeeper服务注册情况u003Cu002Fstrongu003Eu003Cu002Fh2u003Eu003Cimg src=”http:u002Fu002Fp3.pstatp.comu002Flargeu002Fpgc-imageu002FReZhWvyDlpmsAZ” img_width=”515″ img_height=”142″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003Eu003Cpu003Eu003Cstrong toutiao-origin=”span” class=”highlight-text”u003E六、通过浏览器发送请求u003Cu002Fstrongu003E(dubbo-provider的服务注册到Zookeeper上,dubbo-consumer消费者可以调用注册的服务)。u003Cu002Fpu003Eu003Cimg src=”http:u002Fu002Fp1.pstatp.comu002Flargeu002Fpgc-imageu002FReZhXDk6NPykaH” img_width=”600″ img_height=”210″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003Eu003Cpu003E到此,rpc远程调用服务通了!感兴趣的话可以去学习下。u003Cu002Fpu003Eu003Cpu003Eu003Cstrongu003EDemo 源码获取方式:u003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-1″u003E关注u003Cu002Fiu003Eu003Ci class=”chrome-extension-mutihighlight chrome-extension-mutihighlight-style-1″u003E微信u003Cu002Fiu003E公众号「Java后端 」,回复「DZ」获取u003Cu002Fstrongu003Eu003Cu002Fpu003Eu003Cpu003E-END-u003Cu002Fpu003Eu003Cimg src=”http:u002Fu002Fp3.pstatp.comu002Flargeu002Fpgc-imageu002FReU3KFq9FXVax2″ img_width=”1071″ img_height=”742″ alt=”「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架” inline=”0″u003E”

原文始发于:「附源码」Dubbo+Zookeeper 的 RPC 远程调用框架

主题测试文章,只做测试使用。发布者:℅傍ㄖ免沦陷dε鬼,转转请注明出处:http://www.cxybcw.com/17952.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code