RPC远程调用——Dubbo
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的更多相关文章
- 測试JSON RPC远程调用(JSONclient)
#include <string> #include <iostream> #include <curl/curl.h> /* 标题:JSonclient Auth ...
- 使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)
写在前面 阅读本文首先得具备基本的Socket.反射.Java流操作的基本API使用知识:否则本文你可能看不懂... 服务端的端口监听 进行远程调用,那就必须得有客户端和服务端.服务端负责提供服务,客 ...
- 从0到1:全面理解RPC远程调用
上一篇关于 WSGI 的硬核长文,不知道有多少同学,能够从头看到尾的,不管你们有没有看得很过瘾,反正我是写得很爽,总有一种将一样知识吃透了的错觉. 今天我又给自己挖坑了,打算将 rpc 远程调用的知识 ...
- Openstack Nova 源码分析 — RPC 远程调用过程
目录 目录 Nova Project Services Project 的程序入口 setuppy Nova中RPC远程过程调用 nova-compute RPC API的实现 novacompute ...
- dubbo集成zookeeper rpc远程调用
注:下面使用dubbo依赖的是zookeeper注册中心,这里没有详细的介绍.在配置之前,请自行准备好zookeeper环境. 后续如果写zookeeper的配置会补放链接 添加Gradle依赖 co ...
- rpc远程调用开发
RPC即远程过程调用,适用于集群管理,集群节点就是RPCServer,而我们发起远程调用的web服务器就是RPCClient.所以是少数rpcClient(可能一个)对多个RPCServer(集群节点 ...
- Docker+Dubbo+Zookeeper实现RPC远程调用
Docker+Dubbo+Zookeeper 1.安装Docker 1.1卸载旧版本的Docker //如果Docker处于与运行状态 未运行可跳过 [root@MrADiao ~]# systemc ...
- 详解RPC远程调用和消息队列MQ的区别
PC(Remote Procedure Call)远程过程调用,主要解决远程通信间的问题,不需要了解底层网络的通信机制. RPC框架 知名度较高的有Thrift(FB的).dubbo(阿里的). RP ...
- go语言net包rpc远程调用的使用
一.基于http的RPC 服务端: package main; import ( "net/rpc" "net/http" "log" ) ...
随机推荐
- Python Installing Jupyter
Jupyter说明jupyter notebook是一款网页版的Python编辑器组件,便于学习Python Jupyer安装yum -y install gcc gcc-c++ kernel-dev ...
- JMeter5.1开发TCP协议接口脚本
最简单的方法,就是找开发给报文,直接复制到tcp取样器中,将需要变化的值做参数化就可以了.(xml报文要去掉回车换行) 下面是一个通讯头定义 通讯头56个字节(1个字符一个字节) 3 + 9 + 9 ...
- Tensor是神马?为什么还会Flow?
https://baijiahao.baidu.com/s?id=1568147583188426&wfr=spider&for=pc 也许你已经下载了TensorFlow,而且准备开 ...
- Dubbo2.6.5入门——简单的HelloWorld
建立父工程 打开idea,新建一个空的maven工程,作为整个项目的父工程. <?xml version="1.0" encoding="UTF-8"?& ...
- [报错]java.lang.ClassCastException
Caused by: java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to ...
- GIT-Bonobo.Git.Server的使用
GIT-Bonobo.Git.Server的使用 登录 (默认用户:admin/admin) 创建用户: 创建团队,勾选用户 创建新库 保存完成!
- 模板方法模式-Template Method(Java实现)
模板方法模式-Template Method 在模板模式中, 处理的流程被定义在父类中, 而具体的处理则交给了子类. 类关系图很简单: Template接口 这里定义了子类需要实现的方法(before ...
- [Android] Android Java String 转Uri
Uri uri = Uri.parse("https://www.baidu.com") URI uri = new URI("https://www.baidu.com ...
- AWT 新建窗口
新建一个窗口 包 import java.awt.*; 定义 Frame frm_Draw = new Frame("Text"); 初始化代码 public void Frame ...
- 获取多<a/>标签id值的点击事件
<li> <div class="pic"> <c:if test="${userId != null }"> <a ...