Dubbox是什么

Dubbox是一个分布式服务框架,前身是阿里巴巴的开源项目Dubbo,后来阿里不再维护此框架;进而当当网进行了进一步维护,为了和Dubbo区分就取名为Dubbox。

简单而言,在Dubbox中主要存在三种角色:注册中心(Registry)、 提供者(Provider)、消费者(Customer)。

而作为分布式框架之一的Dubbox就能够实现消费方和提供方之间的远程调用,即对分别部署在不同服务器端的服务提供了一个相互交互的平台。

  

  节点角色说明:   

      Provider: 暴露服务的提供方

      Consumer: 调用远程服务的服务消费方

      Registry: 服务注册与发现的注册中心

      Monitor: 统计服务调用次数和调用时间的监控中心

      Container: 服务运行容器

  调用关系说明: 

      服务容器负责启动、加载,运行服务提供者

      服务提供者在启动时,向注册中心注册自己提供的服务

      服务消费者在启动时,向注册中心订阅自己所需的服务

      注册中心返回返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。

      服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台

      服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。

Dubbox实例

  生产者

    导入依赖:

 View Code

接口:

 接口实现类:

配置文件

复制代码
<?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="dubbox-provider"/>
    <!--注册中心地址-->
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
    <!--dubbo服务端口-->
    <dubbo:protocol name="rest" port="8081"/>

    <!--服务注册-->
    <dubbo:service interface="com.dubbo.service.DoSomeService" ref="doSomeService"/>
    <bean id="doSomeService" class="com.dubbo.service.impl.DoSomeServiceImpl"/>

</beans>
复制代码

测试:

 结果:

 消费者

    导入依赖:

      依赖与生产者相同;

    接口:

 配置文件:

复制代码
<?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="dubbox-consumer"/>
    <!--注册中心地址-->
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
    <!--服务消费-->
    <dubbo:reference interface="com.dubbo.service.DoSomeService" id="doSomeService"/>
</beans>
复制代码

测试:

 结果:

 

posted on 2019-12-10 08:33  神剑战王  阅读(365)  评论(0编辑  收藏  举报