1.安装Zookeeper

  a.下载Zookeeper后解压

  b.进入根目录下的conf文件夹,将zoo_sample.cfg改成bak文件,并复制一个修改为zoo.cfg,修改相关配置

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#此处设置data和log的路径
dataDir=D:/JavaTools/zookeeper/server1/zookeeper-3.4.11/zooData
dataLogDir=D:/JavaTools/zookeeper/server1/zookeeper-3.4.11/zooLog
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

  c.进入bin目录,双击zkServer.cmd启动Zookeeper(关闭窗口则停止)

2.创建服务端

  a.导入依赖

  <dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.5</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>

  b.创建服务接口

public interface DubboServer {
public String hello(String name);
}

  c.创建接口实现类

public class DubboServerImp implements DubboServer {
@Override
public String hello(String name) {
return "hello"+name;
}
}

  d.创建spring-dubbo-provider.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
">
<!-- 提供方应用名称信息,这个相当于起一个名字,在dubbo管理页面比较清晰是哪个应用暴露出来的 -->
<dubbo:application name="user_provider"/>
<!-- 使用zookeeper注册中心注册服务 -->
<dubbo:registry address="zookeeper://localhost:2181"/> <dubbo:protocol name="dubbo" port="20880"/> <!-- <dubbo:monitor protocol="registry"/> -->
<!-- 暴露的服务接口 -->
<dubbo:service interface="com.wode.server.DubboServer"
ref="dubboServer" timeout="5000" retries="2" /> <bean id="dubboServer" class="com.wode.server.imp.DubboServerImp" /> </beans>

3.创建客户端

  a.引入相同的依赖

    <dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.5</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>

  b.复制粘贴服务端的接口

public interface DubboServer {
public String hello(String name);
}

  c.创建spring-dubbo-client.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
"> <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="user_consumer" /> <dubbo:registry address="zookeeper://localhost:2181"/>
<!-- <dubbo:monitor protocol="registry"/> --> <!-- 注册中心配置 -->
<dubbo:reference id="dubboServer" interface="com.wode.server.DubboServer" timeout="10000" check="false" /> </beans>

  d.调用服务

@Controller
public class DubboTestController { @Resource
DubboServer server; //根据查询信息
@RequestMapping("/getMsg")
public @ResponseBody String getMsg(HttpSession session, HttpServletRequest request,HttpServletResponse response){
String keyWord = request.getParameter("keyWord");
//调用服务
String result = server.hello(keyWord);
return result;
} }

注意:服务端和客户端的接口名称务必保持一致,连包名都要一致,不然会报Please check registry access list (whitelist/blacklist)的异常

RPC远程调用——Dubbo的更多相关文章

  1. 測试JSON RPC远程调用(JSONclient)

    #include <string> #include <iostream> #include <curl/curl.h> /* 标题:JSonclient Auth ...

  2. 使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)

    写在前面 阅读本文首先得具备基本的Socket.反射.Java流操作的基本API使用知识:否则本文你可能看不懂... 服务端的端口监听 进行远程调用,那就必须得有客户端和服务端.服务端负责提供服务,客 ...

  3. 从0到1:全面理解RPC远程调用

    上一篇关于 WSGI 的硬核长文,不知道有多少同学,能够从头看到尾的,不管你们有没有看得很过瘾,反正我是写得很爽,总有一种将一样知识吃透了的错觉. 今天我又给自己挖坑了,打算将 rpc 远程调用的知识 ...

  4. Openstack Nova 源码分析 — RPC 远程调用过程

    目录 目录 Nova Project Services Project 的程序入口 setuppy Nova中RPC远程过程调用 nova-compute RPC API的实现 novacompute ...

  5. dubbo集成zookeeper rpc远程调用

    注:下面使用dubbo依赖的是zookeeper注册中心,这里没有详细的介绍.在配置之前,请自行准备好zookeeper环境. 后续如果写zookeeper的配置会补放链接 添加Gradle依赖 co ...

  6. rpc远程调用开发

    RPC即远程过程调用,适用于集群管理,集群节点就是RPCServer,而我们发起远程调用的web服务器就是RPCClient.所以是少数rpcClient(可能一个)对多个RPCServer(集群节点 ...

  7. Docker+Dubbo+Zookeeper实现RPC远程调用

    Docker+Dubbo+Zookeeper 1.安装Docker 1.1卸载旧版本的Docker //如果Docker处于与运行状态 未运行可跳过 [root@MrADiao ~]# systemc ...

  8. 详解RPC远程调用和消息队列MQ的区别

    PC(Remote Procedure Call)远程过程调用,主要解决远程通信间的问题,不需要了解底层网络的通信机制. RPC框架 知名度较高的有Thrift(FB的).dubbo(阿里的). RP ...

  9. go语言net包rpc远程调用的使用

    一.基于http的RPC 服务端: package main; import ( "net/rpc" "net/http" "log" ) ...

随机推荐

  1. rest framework 认证 权限 频率

    认证组件 发生位置 APIview 类种的 dispatch 方法执行到 initial 方法 进行 认证组件认证 源码位置 rest_framework.authentication  源码内部需要 ...

  2. Vue笔记:使用 axios 中 this 指向问题

    问题背景 在vue中使用axios做网络请求的时候,会遇到this不指向vue,而为undefined. 如下图所示,我们有一个 login 方法,希望在登录成功之后路由到主页,但通过 this.$r ...

  3. MFC(2):Edit Control 实现自动换行

    --------------------------------------- 设置属性: multiline:  true Auto_HScroll:true Vertical scroll: tr ...

  4. DirectX11 With Windows SDK--07 添加光照与常用几何模型

    前言 对于3D游戏来说,合理的光照可以让游戏显得更加真实.接下来会介绍光照的各种分量,以及常见的光照模型.除此之外,该项目还用到了多个常量缓冲区,因此还会提及HLSL的常量缓冲区打包规则以及如何设置多 ...

  5. [物理学与PDEs]第2章第2节 粘性流体力学方程组 2.3 广义 Newton 法则---本构方程

    1.  ${\bf P}=(p_{ij})$, 而 $$\bex p_{ij}=-p\delta_{ij}+\tau_{ij}, \eex$$ 其中 $\tau_{ij}$ 对应于摩擦切应力. 2. ...

  6. 自定义border 为 dashed 时的虚线间距

    li{ width: 100%; height: 3px; background-image: linear-gradient(to right, #009a61 0%, #009a61 50%, t ...

  7. react-router v4 按需加载的配置方法

    在react项目开发中,当访问默认页面时会一次性请求所有的js资源,这会大大影响页面的加载速度和用户体验.所以添加按需加载功能是必要的,以下是配置按需加载的方法: 安装bundle-loader np ...

  8. idea远程tomcat运行项目

    记录一下idea远程tomcat运行项目的配置过程 背景:每次系统修改代码后则需手动打包手动部署到测试服务器上,为了简化这个过程我这里选择尝试一次idea的远程运行功能,结论来讲这玩意配置麻烦,并不算 ...

  9. win10下maven的安装与配置

    下载apache-maven-3.5.3-bin.zip并解压: 环境配置: 系统环境:添加=>MAVEN_HOME 值为apache-maven-3.5.3的路径(D:\xxx\apache- ...

  10. 第八节,Opencv的基本使用------存取图像、视频功能、简单信息标注工具

    1.存取图像 import cv2 img=cv2.imread('test.jpg') cv2.imwrite('test1.jpg',img) 2.图像的仿射变换 图像的仿射变换涉及图像的形状位置 ...