dubbox「建议收藏」

dubbox「建议收藏」Dubbox是什么Dubbox是一个分布式服务框架,前身是阿里巴巴的开源项目Dubbo,后来阿里不再维护此框架;进而当当网进行了进一步维护,为了和Dubbo区分就取名为Dubbox。简单而言,在Dubbox中主要存在三种角色:注册中心(Registry)、提供者(Provider)、消费者(Customer)。而作为分布式框架之一的Dubbox就能够实现消费方和提供方之间的远程调用,即对分…

大家好,欢迎来到IT知识分享网。

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

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

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

节点角色说明:   
      Provider: 暴露服务的提供方

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

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

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

Container: 服务运行容器

调用关系说明: 
      服务容器负责启动、加载,运行服务提供者

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

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

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

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

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

Dubbox实例
  生产者
    导入依赖:

复制代码

 <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>dubbo</artifactId>
      <version>2.8.4</version>
    </dependency>
    <!-- 添加zk客户端依赖 -->
    <dependency>
      <groupId>com.github.sgroschupf</groupId>
      <artifactId>zkclient</artifactId>
      <version>0.1</version>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>3.0.7.Final</version>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-client</artifactId>
      <version>3.0.7.Final</version>
    </dependency>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>1.0.0.GA</version>
    </dependency>

    <!-- 如果要使用json序列化 -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jackson-provider</artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <!-- 如果要使用xml序列化 -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxb-provider</artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <!-- 如果要使用netty server -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-netty</artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <!-- 如果要使用Sun HTTP server -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jdk-http</artifactId>
      <version>3.0.7.Final</version>
    </dependency>

    <!-- 如果要使用tomcat server -->
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-core</artifactId>
      <version>8.0.11</version>
    </dependency>
    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId>tomcat-embed-logging-juli</artifactId>
      <version>8.0.11</version>
    </dependency>
    <dependency>
      <groupId>com.esotericsoftware.kryo</groupId>
      <artifactId>kryo</artifactId>
      <version>2.24.0</version>
    </dependency>
    <dependency>
      <groupId>de.javakaffee</groupId>
      <artifactId>kryo-serializers</artifactId>
      <version>0.26</version>
    </dependency>
    <dependency>
      <groupId>de.ruedigermoeller</groupId>
      <artifactId>fst</artifactId>
      <version>1.55</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.3.3</version>
    </dependency>
    <dependency>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jetty</artifactId>
      <version>7.0.0.pre5</version>
    </dependency>
    <dependency>
      <groupId>com.dubbo</groupId>
      <artifactId>dubbox_service</artifactId>
      <version>1.0-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>

接口:

在这里插入图片描述

接口实现类:

在这里插入图片描述

配置文件

复制代码

<?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>

复制代码
测试:
在这里插入图片描述
结果:
在这里插入图片描述

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/26253.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信