Multicast 注册中心不须要启动任何中心节点,只要广播地址同样,就能够互相发现。html
unicast=false
,则广播给订阅者组播受网络结构限制,只适合小规模应用或开发阶段使用。组播地址段: 224.0.0.0 - 239.255.255.255git
配置github
<dubbo:registry address="multicast://224.5.6.7:1234" />
或redis
<dubbo:registry protocol="multicast" address="224.5.6.7:1234" />
为了减小广播量,Dubbo 缺省使用单播发送提供者地址信息给消费者,若是一个机器上同时启了多个消费者进程,消费者需声明 unicast=false,不然只会有一个消费者能收到消息:spring
<dubbo:registry address="multicast://224.5.6.7:1234?unicast=false" />
或数据库
<dubbo:registry protocol="multicast" address="224.5.6.7:1234">
<dubbo:parameter key="unicast" value="false" />
</dubbo:registry>
Zookeeper 是 Apacahe Hadoop 的子项目,是一个树型的目录服务,支持变动推送,适合做为 Dubbo 服务的注册中心,工业强度较高,可用于生产环境,并推荐使用 1。apache
流程说明:服务器
支持如下功能:网络
使用数据结构
在 provider 和 consumer 中增长 zookeeper 客户端 jar 包依赖:
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.3.3</version>
</dependency>
Dubbo 支持 zkclient 和 curator 两种 Zookeeper 客户端实现:
使用 zkclient 客户端
从 2.2.0 版本开始缺省为 zkclient 实现,以提高 zookeeper 客户端的健状性。zkclient 是 Datameer 开源的一个 Zookeeper 客户端实现。
缺省配置:
<dubbo:registry ... client="zkclient" />
或:
dubbo.registry.client=zkclient
或:
zookeeper://10.20.153.10:2181?client=zkclient
需依赖或直接下载:
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
使用 curator 客户端
从 2.3.0 版本开始支持可选 curator 实现。Curator 是 Netflix 开源的一个 Zookeeper 客户端实现。
若是须要改成 curator 实现,请配置:
<dubbo:registry ... client="curator" />
或:
dubbo.registry.client=curator
或:
zookeeper://10.20.153.10:2181?client=curator
需依赖或直接下载:
<dependency>
<groupId>com.netflix.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>1.1.10</version>
</dependency>
Zookeeper 单机配置:
<dubbo:registry address="zookeeper://10.20.153.10:2181" />
或:
<dubbo:registry protocol="zookeeper" address="10.20.153.10:2181" />
Zookeeper 集群配置:
<dubbo:registry address="zookeeper://10.20.153.10:2181?backup=10.20.153.11:2181,10.20.153.12:2181" />
或:
<dubbo:registry protocol="zookeeper" address="10.20.153.10:2181,10.20.153.11:2181,10.20.153.12:2181" />
同一 Zookeeper,分红多组注册中心:
<dubbo:registry id="chinaRegistry" protocol="zookeeper" address="10.20.153.10:2181" group="china" />
<dubbo:registry id="intlRegistry" protocol="zookeeper" address="10.20.153.10:2181" group="intl" />
zookeeper 安装
安装方式参见: Zookeeper安装手册,只需搭一个原生的 Zookeeper 服务器,并将 Quick Start 中 Provider 和 Consumer 里的 conf/dubbo.properties 中的 dubbo.registry.addrss 的值改成 zookeeper://127.0.0.1:2181 便可使用。
可靠性声明
阿里内部并无采用 Zookeeper 作为注册中心,而是使用本身实现的基于数据库的注册中心,即:Zookeeper 注册中心并无在阿里内部长时间运行的可靠性保障,此 Zookeeper 桥接实现只为开源版本提供,其可靠性依赖于 Zookeeper 自己的可靠性。
兼容性声明
因 2.0.8 最初设计的 zookeeper 存储结构不能扩充不一样类型的数据,2.0.9 版本作了调整,因此不兼容,需所有改用 2.0.9 版本才行,之后的版本会保持兼容 2.0.9。2.2.0 版本改成基于 zkclient 实现,需增长 zkclient 的依赖包,2.3.0 版本增长了基于 curator 的实现,做为可选实现策略。
基于 Redis(是一个高效的 KV 存储服务器)实现的注册中心(从 2.1.0 版本开始支持) 。
使用 Redis 的 Key/Map 结构存储数据结构:
使用 Redis 的 Publish/Subscribe 事件通知数据变动:
调用过程:
配置
<dubbo:registry address="redis://10.20.153.10:6379" />
或
<dubbo:registry address="redis://10.20.153.10:6379?backup=10.20.153.11:6379,10.20.153.12:6379" />
或
<dubbo:registry protocol="redis" address="10.20.153.10:6379" />
或
<dubbo:registry protocol="redis" address="10.20.153.10:6379,10.20.153.11:6379,10.20.153.12:6379" />
选项
可靠性声明
阿里内部并无采用 Redis 作为注册中心,而是使用本身实现的基于数据库的注册中心,即:Redis 注册中心并无在阿里内部长时间运行的可靠性保障,此 Redis 桥接实现只为开源版本提供,其可靠性依赖于 Redis 自己的可靠性。
Simple 注册中心自己就是一个普通的 Dubbo 服务,能够减小第三方依赖,使总体通信方式一致。
配置
将 Simple 注册中心暴露成 Dubbo 服务:
<?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-2.5.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 当前应用信息配置 -->
<dubbo:application name="simple-registry" />
<!-- 暴露服务协议配置 -->
<dubbo:protocol port="9090" />
<!-- 暴露服务配置 -->
<dubbo:service interface="com.alibaba.dubbo.registry.RegistryService" ref="registryService" registry="N/A" ondisconnect="disconnect" callbacks="1000">
<dubbo:method name="subscribe"><dubbo:argument index="1" callback="true" /></dubbo:method>
<dubbo:method name="unsubscribe"><dubbo:argument index="1" callback="false" /></dubbo:method>
</dubbo:service>
<!-- 简单注册中心实现,可自行扩展实现集群和状态同步 -->
<bean id="registryService" class="com.alibaba.dubbo.registry.simple.SimpleRegistryService" />
</beans>
引用 Simple Registry 服务:
<dubbo:registry address="127.0.0.1:9090" />
或者:
<dubbo:service interface="com.alibaba.dubbo.registry.RegistryService" group="simple" version="1.0.0" ... >
或者:
<dubbo:registry address="127.0.0.1:9090" group="simple" version="1.0.0" />
适用性说明
此 SimpleRegistryService 只是简单实现,不支持集群,可做为自定义注册中心的参考,但不适合直接用于生产环境。
参考:
http://dubbo.io/books/dubbo-user-book/references/registry/introduction.html