Dubbo简介
Dubbo是阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和Spring框架无缝集成。具体可以看 百度百科 https://baike.baidu.com/item/Dubbo/18907815?fr=aladdin
Dubbo主页地址 http://dubbo.io/
托管GitHub https://github.com/alibaba/dubbo 我们学习的话 主要看这个github主页。
Dubbo用户手册 http://dubbo.io/books/dubbo-user-book/ Dubbo介绍以及使用方案以及很多的实例;
Dubbo开发指南 http://dubbo.io/books/dubbo-dev-book/ Dubbo底层源码以及设计的介绍;
Dubbo管理手册 http://dubbo.io/books/dubbo-admin-book/ Dubbo注册中心,管理控制台的安装和使用;
下载是Dubbo的简介,内容来自Dubbo用户手册;
背景
随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进。
单一应用架构
当网站流量很小时,只需一个应用,将所有功能都部署在一起,以减少部署节点和成本。此时,用于简化增删改查工作量的数据访问框架(ORM)是关键。
垂直应用架构
当访问量逐渐增大,单一应用增加机器带来的加速度越来越小,将应用拆成互不相干的几个应用,以提升效率。此时,用于加速前端页面开发的Web框架(MVC)是关键。
分布式服务架构
当垂直应用越来越多,应用之间交互不可避免,将核心业务抽取出来,作为独立的服务,逐渐形成稳定的服务中心,使前端应用能更快速的响应多变的市场需求。此时,用于提高业务复用及整合的分布式服务框架(RPC)是关键。
流动计算架构
当服务越来越多,容量的评估,小服务资源的浪费等问题逐渐显现,此时需增加一个调度中心基于访问压力实时管理集群容量,提高集群利用率。此时,用于提高机器利用率的资源调度和治理中心(SOA)是关键。
需求
在大规模服务化之前,应用可能只是通过 RMI 或 Hessian 等工具,简单的暴露和引用远程服务,通过配置服务的URL地址进行调用,通过 F5 等硬件进行负载均衡。
当服务越来越多时,服务 URL 配置管理变得非常困难,F5 硬件负载均衡器的单点压力也越来越大。 此时需要一个服务注册中心,动态的注册和发现服务,使服务的位置透明。并通过在消费方获取服务提供方地址列表,实现软负载均衡和 Failover,降低对 F5 硬件负载均衡器的依赖,也能减少部分成本。
当进一步发展,服务间依赖关系变得错踪复杂,甚至分不清哪个应用要在哪个应用之前启动,架构师都不能完整的描述应用的架构关系。 这时,需要自动画出应用间的依赖关系图,以帮助架构师理清理关系。
接着,服务的调用量越来越大,服务的容量问题就暴露出来,这个服务需要多少机器支撑?什么时候该加机器? 为了解决这些问题,第一步,要将服务现在每天的调用量,响应时间,都统计出来,作为容量规划的参考指标。其次,要可以动态调整权重,在线上,将某台机器的权重一直加大,并在加大的过程中记录响应时间的变化,直到响应时间到达阀值,记录此时的访问量,再以此访问量乘以机器数反推总容量。
以上是 Dubbo 最基本的几个需求。
架构
节点角色说明
节点 | 角色说明 |
---|---|
Provider |
暴露服务的服务提供方 |
Consumer |
调用远程服务的服务消费方 |
Registry |
服务注册与发现的注册中心 |
Monitor |
统计服务的调用次数和调用时间的监控中心 |
Container |
服务运行容器 |
调用关系说明
服务容器负责启动,加载,运行服务提供者。
服务提供者在启动时,向注册中心注册自己提供的服务。
服务消费者在启动时,向注册中心订阅自己所需的服务。
注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。
服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。
服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。
Dubbo 架构具有以下几个特点,分别是连通性、健壮性、伸缩性、以及向未来架构的升级性。
连通性
注册中心负责服务地址的注册与查找,相当于目录服务,服务提供者和消费者只在启动时与注册中心交互,注册中心不转发请求,压力较小
监控中心负责统计各服务调用次数,调用时间等,统计先在内存汇总后每分钟一次发送到监控中心服务器,并以报表展示
服务提供者向注册中心注册其提供的服务,并汇报调用时间到监控中心,此时间不包含网络开销
服务消费者向注册中心获取服务提供者地址列表,并根据负载算法直接调用提供者,同时汇报调用时间到监控中心,此时间包含网络开销
注册中心,服务提供者,服务消费者三者之间均为长连接,监控中心除外
注册中心通过长连接感知服务提供者的存在,服务提供者宕机,注册中心将立即推送事件通知消费者
注册中心和监控中心全部宕机,不影响已运行的提供者和消费者,消费者在本地缓存了提供者列表
注册中心和监控中心都是可选的,服务消费者可以直连服务提供者
健状性
监控中心宕掉不影响使用,只是丢失部分采样数据
数据库宕掉后,注册中心仍能通过缓存提供服务列表查询,但不能注册新服务
注册中心对等集群,任意一台宕掉后,将自动切换到另一台
注册中心全部宕掉后,服务提供者和服务消费者仍能通过本地缓存通讯
服务提供者无状态,任意一台宕掉后,不影响使用
服务提供者全部宕掉后,服务消费者应用将无法使用,并无限次重连等待服务提供者恢复
伸缩性
注册中心为对等集群,可动态增加机器部署实例,所有客户端将自动发现新的注册中心
服务提供者无状态,可动态增加机器部署实例,注册中心将推送新的服务提供者信息给消费者
升级性
当服务集群规模进一步扩大,带动IT治理结构进一步升级,需要实现动态部署,进行流动计算,现有分布式服务架构不会带来阻力。下图是未来可能的一种架构:
节点角色说明
节点 | 角色说明 |
---|---|
Deployer |
自动部署服务的本地代理 |
Repository |
仓库用于存储服务应用发布包 |
Scheduler |
调度中心基于访问压力自动增减服务提供者 |
Admin |
统一管理控制台 |
Registry |
服务注册与发现的注册中心 |
Monitor |
统计服务的调用次数和调用时间的监控中心 |
zookeeper安装
再安装zookeeper之前,我们看下zookeeper简介 https://baike.baidu.com/item/zookeeper/4836397?fr=aladdin
再Dubbo中 官方推荐用zookeeper作为注册中心,我们来安装下zookeeper;
zookeeper支持windows中运行,也支持linux中运行,开发的时候,我们可以用windows,但是企业项目运行,基本都是linux,我们基础课程讲的话 为了方便,直接 windows解压运行。后面实战项目课程,都是Linux下运行;运行原理一样的,一个是启动bat,linux下启动sh即可;大伙linux基础不行的话,补下知识;
zookeeper主页 http://zookeeper.apache.org/
找到下载页面 镜像http下载 下载一个稳定版本 zookeeper-3.4.11.tar.gz 其他测试版本不要下载;
我们演示下windows下的zookeeper的运行;
解压zookeeper-3.4.11.tar.gz
我们执行运行bin目录下的zkServer.cmd (linux下是zkServer.sh)
运行时候是一闪而过,说明启动报错了;
我们要看具体错误信息的话,用记事本打开zkServer.cmd文件;
文件最后,加个pause暂停即可;
我们再运行zkServer.cmd
可以看到报错信息:
主要的意思就是 conf下没有找到zoo.cfg文件;
我们再看下conf目录下;
有个zoo_sample.cfg文件,这个是一个demo文件,zookeeper官方的意思,这个是一个demo配置文件,我们可以自定义配置,我们暂时不细讲zookeeper,所以直接吧 zoo_sample.cfg改成zoo.cfg即可;
改完之后,我们再启动zkServer.cfg,如图:
说明启动成功了,这里的2181是zookeeper的默认端口,刚才的zoo.cfg里,我们可以配置;
具体测试,我们后面讲到发布服务,可以真正看到效果;
发布Dubbo服务
我们现在来学习下发布Dubbo服务,主要参考dubbo开发包里的demo源码;由浅入深的讲解下这个小demo;
详细****,请看 http://www.java1234.com/a/yuanchuang/dubbo/
首先创建一个maven项目dubbo-demo-provider
pom.xml加入依赖:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
< dependencies >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >dubbo</ artifactId >
< version >2.6.0</ version >
</ dependency >
< dependency >
< groupId >com.101tec</ groupId >
< artifactId >zkclient</ artifactId >
< version >0.10</ version >
</ dependency >
< dependency >
< groupId >org.apache.curator</ groupId >
< artifactId >curator-framework</ artifactId >
< version >4.0.1</ version >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >fastjson</ artifactId >
< version >1.2.46</ version >
</ dependency >
< dependency >
< groupId >log4j</ groupId >
< artifactId >log4j</ artifactId >
< version >1.2.17</ version >
</ dependency >
< dependency >
< groupId >org.slf4j</ groupId >
< artifactId >slf4j-api</ artifactId >
< version >1.7.25</ version >
</ dependency >
< dependency >
< groupId >org.apache.commons</ groupId >
< artifactId >commons-lang3</ artifactId >
< version >3.4</ version >
</ dependency >
< dependency >
< groupId >io.netty</ groupId >
< artifactId >netty-all</ artifactId >
< version >4.0.35.Final</ version >
</ dependency >
</ dependencies >
|
然后定义一个服务接口:
1
2
3
4
5
6
7
8
9
10
11
|
package com.java1234.service;
/** * 服务提供者接口
* @author Administrator
*
*/
public interface DemoProviderService {
public String sayHello(String name);
} |
再定义接口实现类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
package com.java1234.service.impl;
import com.java1234.service.DemoProviderService;
/** * 服务提供者接口实现类
* @author Administrator
*
*/
public class DemoProviderServiceImpl implements DemoProviderService{
public String sayHello(String name) {
return "服务员001" ;
}
} |
然后再搞个dubbo配置文件dubbo-demo-provider.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<? xml version = "1.0" encoding = "UTF-8" ?>
< beans xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo = "http://code.alibabatech.com/schema/dubbo"
xmlns = "http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 提供方应用名称, 用于计算依赖关系 -->
< dubbo:application name = "demo-provider" />
<!-- 使用zookeeper注册中心暴露服务地址 -->
< dubbo:registry address = "zookeeper://127.0.0.1:2181" />
<!-- 使用dubbo协议在20880端口暴露服务 -->
< dubbo:protocol name = "dubbo" port = "20880" />
<!-- service实现类作为本地的一个bean -->
< bean id = "demoProviderService" class = "com.java1234.service.impl.DemoProviderServiceImpl" />
<!-- 声明需要暴露的服务接口 -->
< dubbo:service interface = "com.java1234.service.DemoProviderService" ref = "demoProviderService" />
</ beans >
|
测试类:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import java.io.IOException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ProviderTest {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[]{ "dubbo-demo-provider.xml" });
context.start();
System.out.println( "服务提供者注册成功(端口:20880)" );
try {
System.in.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
context.close();
}
} |
然后我们测试发布dubbo服务,
首先我们要先启动zookeeper服务,
然后我们运行测试类,发布服务注册到zookeeper注册中心去;
说明发布服务OK;
Dubbo Admin管理控制台
Dubbo Admin管理控制台
在dubbo发布包里,有个admin项目,
我们可以把这个项目打成war包 然后 发布到tomcat运行;
这里提供打包后的war包 直接下载
链接:https://pan.baidu.com/s/1ggeIIHX 密码:ck4h
这里直接给出最佳实践方法:
用解压缩软件 解压war包:
得到这些,
然后我们解压一个全新的tomcat,我们这里用7
然后webapps下的ROOT里的,我们删除干净
然后把前面war包解压过来的东西 放进去即可,这样我们启动tomcat,首页就是dubbo admin控制台了;很方便;
我们现在可以启动tomcat了 但是启动之前 先吧 zookeeper启动下,否则 启动tomcat 加载dubbo admin会报错,因为默认就检查zookeeper服务,检测不到 就一直报错;
浏览器输入:http://localhost:8080/
要身份认证,默认用户名是root,密码也是root;
登录成功,首页是:
语言可以切换中英文;
比如我们发布一个服务,然后菜单选择服务;可以看到所有发布的dubbo服务信息;
比较方便,其他功能后面再说;
消费Dubbo服务
前面我们搞了发布Dubbo服务,发布的服务就是用来消费的,所以我们这里来调用服务,消费下;
创建maven项目 dubbo-demo-consumer
pom.xml配置下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
< dependencies >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >dubbo</ artifactId >
< version >2.6.0</ version >
</ dependency >
< dependency >
< groupId >com.101tec</ groupId >
< artifactId >zkclient</ artifactId >
< version >0.10</ version >
</ dependency >
< dependency >
< groupId >org.apache.curator</ groupId >
< artifactId >curator-framework</ artifactId >
< version >4.0.1</ version >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >fastjson</ artifactId >
< version >1.2.46</ version >
</ dependency >
< dependency >
< groupId >log4j</ groupId >
< artifactId >log4j</ artifactId >
< version >1.2.17</ version >
</ dependency >
< dependency >
< groupId >org.slf4j</ groupId >
< artifactId >slf4j-api</ artifactId >
< version >1.7.25</ version >
</ dependency >
< dependency >
< groupId >org.apache.commons</ groupId >
< artifactId >commons-lang3</ artifactId >
< version >3.4</ version >
</ dependency >
< dependency >
< groupId >io.netty</ groupId >
< artifactId >netty-all</ artifactId >
< version >4.0.35.Final</ version >
</ dependency >
</ dependencies >
|
再搞个dubbo-demo-consumer.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<? xml version = "1.0" encoding = "UTF-8" ?>
< beans xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo = "http://code.alibabatech.com/schema/dubbo"
xmlns = "http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
< dubbo:application name = "demo-consumer" />
<!-- 使用zookeeper注册中心暴露服务地址 -->
< dubbo:registry address = "zookeeper://127.0.0.1:2181" />
<!-- 生成远程服务代理,可以和本地bean一样使用demoProviderService check属性,启动的时候是否检查 一般设置为false 启动的时候不检查-->
< dubbo:reference id = "demoProviderService" check = "false" interface = "com.java1234.service.DemoProviderService" />
</ beans >
|
创建接口DemoProviderService.java
1
2
3
4
5
6
7
8
9
10
11
|
package com.java1234.service;
/** * 服务提供者接口
* @author Administrator
*
*/
public interface DemoProviderService {
public String sayHello(String name);
} |
搞个测试类ConsumerTest:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import java.io.IOException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.java1234.service.DemoProviderService;
public class ConsumerTest {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[]{ "dubbo-demo-consumer.xml" });
context.start();
DemoProviderService demoProviderService=(DemoProviderService) context.getBean( "demoProviderService" );
String result=demoProviderService.sayHello( "你好" );
System.out.println( "远程调用结果:" +result);
try {
System.in.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
context.close();
}
} |
运行结果 远程调用结果:服务001
说明远程调用成功;
接口抽取及依赖版本统一
前面的项目,我们会发现有个接口是一样的,我们需要单独抽取出来,统一维护;
以及两个项目的maven依赖包的版本也是一样的,我们也需要单独抽取出来,统一维护;
抽取接口,我们通过新建一个项目,然后其他两个项目依赖这个这个项目即可;
统一依赖包版本,我们可以通过建立parent项目,来统一管理依赖以及版本,子项目继承即可;
我们新建dubbo-demo-api项目,然后把DemoProviderService接口类放到该项目里即可;
我们再新建一个dubbo-demo-parent项目;
pom.xml里:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
< 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.java1234</ groupId >
< artifactId >dubbo-demo-parent</ artifactId >
< version >0.0.1-SNAPSHOT</ version >
< packaging >pom</ packaging >
<!-- 依赖版本管理 -->
< properties >
< dubbo-demo-api.version >0.0.1-SNAPSHOT</ dubbo-demo-api.version >
< dubbo.version >2.6.0</ dubbo.version >
< zkclient.version >0.10</ zkclient.version >
< curator-framework.version >4.0.1</ curator-framework.version >
< fastjson.version >1.2.46</ fastjson.version >
< log4j.version >1.2.17</ log4j.version >
< slf4j-api.version >1.7.25</ slf4j-api.version >
< commons-lang3.version >3.4</ commons-lang3.version >
< netty-all.version >4.0.35.Final</ netty-all.version >
</ properties >
<!-- 依赖管理-->
< dependencyManagement >
< dependencies >
< dependency >
< groupId >com.java1234</ groupId >
< artifactId >dubbo-demo-api</ artifactId >
< version >${dubbo-demo-api.version}</ version >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >dubbo</ artifactId >
< version >${dubbo.version}</ version >
</ dependency >
< dependency >
< groupId >com.101tec</ groupId >
< artifactId >zkclient</ artifactId >
< version >${zkclient.version}</ version >
</ dependency >
< dependency >
< groupId >org.apache.curator</ groupId >
< artifactId >curator-framework</ artifactId >
< version >${curator-framework.version}</ version >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >fastjson</ artifactId >
< version >${fastjson.version}</ version >
</ dependency >
< dependency >
< groupId >log4j</ groupId >
< artifactId >log4j</ artifactId >
< version >${log4j.version}</ version >
</ dependency >
< dependency >
< groupId >org.slf4j</ groupId >
< artifactId >slf4j-api</ artifactId >
< version >${slf4j-api.version}</ version >
</ dependency >
< dependency >
< groupId >org.apache.commons</ groupId >
< artifactId >commons-lang3</ artifactId >
< version >${commons-lang3.version}</ version >
</ dependency >
< dependency >
< groupId >io.netty</ groupId >
< artifactId >netty-all</ artifactId >
< version >${netty-all.version}</ version >
</ dependency >
</ dependencies >
</ dependencyManagement >
</ project >
|
dubbo-demo-provider项目pom.xml修改:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
< 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 >
< parent >
< groupId >com.java1234</ groupId >
< artifactId >dubbo-demo-parent</ artifactId >
< version >0.0.1-SNAPSHOT</ version >
</ parent >
< artifactId >dubbo-demo-provider</ artifactId >
< dependencies >
< dependency >
< groupId >com.java1234</ groupId >
< artifactId >dubbo-demo-api</ artifactId >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >dubbo</ artifactId >
</ dependency >
< dependency >
< groupId >com.101tec</ groupId >
< artifactId >zkclient</ artifactId >
</ dependency >
< dependency >
< groupId >org.apache.curator</ groupId >
< artifactId >curator-framework</ artifactId >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >fastjson</ artifactId >
</ dependency >
< dependency >
< groupId >log4j</ groupId >
< artifactId >log4j</ artifactId >
</ dependency >
< dependency >
< groupId >org.slf4j</ groupId >
< artifactId >slf4j-api</ artifactId >
</ dependency >
< dependency >
< groupId >org.apache.commons</ groupId >
< artifactId >commons-lang3</ artifactId >
</ dependency >
< dependency >
< groupId >io.netty</ groupId >
< artifactId >netty-all</ artifactId >
</ dependency >
</ dependencies >
</ project >
|
类似,dubbo-demo-consumer项目pom.xml修改:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
< 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 >
< parent >
< groupId >com.java1234</ groupId >
< artifactId >dubbo-demo-parent</ artifactId >
< version >0.0.1-SNAPSHOT</ version >
</ parent >
< artifactId >dubbo-demo-consumer</ artifactId >
< dependencies >
< dependency >
< groupId >com.java1234</ groupId >
< artifactId >dubbo-demo-api</ artifactId >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >dubbo</ artifactId >
</ dependency >
< dependency >
< groupId >com.101tec</ groupId >
< artifactId >zkclient</ artifactId >
</ dependency >
< dependency >
< groupId >org.apache.curator</ groupId >
< artifactId >curator-framework</ artifactId >
</ dependency >
< dependency >
< groupId >com.alibaba</ groupId >
< artifactId >fastjson</ artifactId >
</ dependency >
< dependency >
< groupId >log4j</ groupId >
< artifactId >log4j</ artifactId >
</ dependency >
< dependency >
< groupId >org.slf4j</ groupId >
< artifactId >slf4j-api</ artifactId >
</ dependency >
< dependency >
< groupId >org.apache.commons</ groupId >
< artifactId >commons-lang3</ artifactId >
</ dependency >
< dependency >
< groupId >io.netty</ groupId >
< artifactId >netty-all</ artifactId >
</ dependency >
</ dependencies >
</ project >
|
测试结果OK;
dubbo服务集群实现负载均衡
当某个服务并发量特别大的时候,一个服务延迟太高,我们就需要进行服务集群,例如某个项目一天注册量10万,这个注册功能就必须要进行集群了,否则一个服务无法应付这么大的并发量;
dubbo的服务集群很简单,只需要配置文件里改个端口即可,其他代码不需要动;
企业级项目多个服务集群,每个服务都放不同机器,不仅能实现负载均衡,也能进行容错;就算一个机器挂了,其他机器可以继续服务;
多个服务也提供权重设置,来动态设置请求分发量;
具体讲解,请看**** http://www.java1234.com/a/yuanchuang/dubbo/
maven pom.xml出现web.xml is missing and is set to true解决方案
最近新建springboot项目,pom.xml报错 web.xml is missing and <failOnMissingWebXml> is set to true
主要项目里没有web.xml,我们只需要配置下
1
2
3
4
5
6
7
|
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-war-plugin</ artifactId >
< configuration >
< failOnMissingWebXml >false</ failOnMissingWebXml >
</ configuration >
</ plugin >
|
忽略web.xml即可;