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" ) ...
随机推荐
- Day046--JavaScript-- DOM操作, js中的面向对象, 定时
一. DOM的操作(创建,追加,删除) parentNode 获取父级标签 nextElementSibling 获取下一个兄弟节点 children 获取所有的子标签 <!DOCTYPEhtm ...
- Day044--javascript, ECMAScript
一. javascript JavaScript基础分为三个部分: ECMAScript:JavaScript的语法标准.包括变量.表达式.运算符.函数.if语句.for语句等. DOM:操作网页上的 ...
- Linux设备树(三 属性)
三 属性(property) device_type = "memory"就是一个属性,等号前边是属性,后边是值.节点是一个逻辑上相对独立的实体,属性是用来描述节点特性的,根据需要 ...
- C#中的Finalize,Dispose,SuppressFinalize的实现和使用介绍
原文地址:http://www.csharpwin.com/csharpspace/8927r1397.shtml MSDN建议按照下面的模式实现IDisposable接口: public class ...
- LaTeX 一个段落加边框
\usepackage{framed} \begin{framed} 对这里加边框啊 \end{framed}
- 使用SO_REVTIMEO套接字选项为recvfrom设置超时
void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen) { int n; ]; struct timeval ...
- Codeforces 1096F(dp + 树状数组)
题目链接 题意: 对于长度为$n$的排列,在已知一些位的前提下求逆序对的期望 思路: 将答案分为$3$部分 $1.$$-1$与$-1$之间对答案的贡献.由于逆序对考虑的是数字之间的大小关系,故假设$- ...
- 子级用了float浮动之后,如何撑开父元素,让父元素div自动适应高度
方法一:对父级设置固定高度 假如以上案例,我们知道内部div高度100px,那对父级设置css height为100px看看效果. 此方法缺点,父级是固定高度,而不随内容高度自适应高度,没高度.此方法 ...
- 一、Kubernetes系列之介绍篇
•Kubernetes介绍 1.背景介绍 云计算飞速发展 - IaaS - PaaS - SaaS Docker技术突飞猛进 - 一次构建,到处运行 - 容器的快速轻量 - 完整的生态环境 2.什 ...
- vue全局引入scss文件(推荐)
<template> <div id="app"> <router-view/> </div> </template> ...