• Dubbo


    1.分布式系统

    分布式系统是若干独立计算机的集合,这计算机对用户来说就像单个相关系统。

    发展历程

    单一应用架构

    扩展不易(如果要修改应用中的某个功能,需要将应用重新打包,重新放在服务器上),协同开发不易(大家都修改,会乱),应用大小变大,给服务器带来压力

    垂直应用架构

    大应用拆成独立小应用(独一的数据库,业务都完整),放在服务器中,哪部分用户访问量大,可将此部分多添加几台服务器

    分布式服务架构

     无法起到监控作用,为了实现服务器之间的合理调度,出现了----->>>>>.

    流动计算架构

     维护服务之间的复杂关系,哪个访问量大,可以动态添加几台服务器,下一次服务进入,优先进入访问量少的服务器来处理请求,提高了服务的利用率。

    RPC(远程过程调用)

     传出序列化,传入反序列化

    2.Dubbo的出现

    18年2月15日

    阿里---》阿帕奇

    特点

    1.面向接口代理的高性能RPC调用

    2.智能负载均衡(内置多种负载均衡策略,显著减少调用延迟,提高系统吞吐量)

    3.服务自动注册与发现(支持多种注册中心,服务实例上下线感知)

    4.高度可扩展能力(微内核+插件原理  ,几乎所有东西都可扩展)

    5.运行期流量调度(通过配置不同路由规则,实现灰色发布--<选定一部分服务器使用新版本的服务,请求进入之后,一部分请求进入新服务,确定没问题后,逐渐将就服务像新服务进行过度,王者体验服与正式服>)

    6.可视化服务治理与运维

     

     将服务提供者注册到注册中心

    引入dubbo依赖与操作zookeeper的客户端curator

    <!-- https://mvnrepository.com/artifact/com.alibaba/dubbo -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
        <version>2.6.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-framework -->
    <dependency>
        <groupId>org.apache.curator</groupId>
        <artifactId>curator-framework</artifactId>
        <version>2.12.0</version>
    </dependency>
    

      

    用 Spring 配置声明暴露服务

    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://dubbo.apache.org/schema/dubbo"
        xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd        http://dubbo.apache.org/schema/dubbo        http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
     
        <!-- 提供方应用信息,用于计算依赖关系 -->
        <dubbo:application name="hello-world-app"  />
     
        <!-- 使用multicast广播注册中心暴露服务地址 -->
        <dubbo:registry address="multicast://224.5.6.7:1234" />
     
        <!-- 用dubbo协议在20880端口暴露服务 -->
        <dubbo:protocol name="dubbo" port="20880" />
     
        <!-- 声明需要暴露的服务接口  ref真正的实现-->
        <dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService" />
     
        <!-- 和本地bean一样实现服务 -->
        <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl" />
    </beans>
    resources/spring/dubbo-provider.xml
    修改其中的dubbo:registry,替换成真实的注册中心地址,推荐使用zookeeper,如:
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>

    加载 Spring 配置

    Provider.java:

    import org.springframework.context.support.ClassPathXmlApplicationContext;
     
    public class Provider {
        public static void main(String[] args) throws Exception {
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"http://10.20.160.198/wiki/display/dubbo/provider.xml"});
            context.start();
            System.in.read(); // 按任意键退出
        }
    }

    通过 Spring 配置引用远程服务

    consumer.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://dubbo.apache.org/schema/dubbo"
        xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd        http://dubbo.apache.org/schema/dubbo        http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
     
        <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
        <dubbo:application name="consumer-of-helloworld-app"  />
     
        <!-- 使用multicast广播注册中心暴露发现服务地址 -->
        <dubbo:registry address="multicast://224.5.6.7:1234" />
     
        <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
        <dubbo:reference id="demoService" interface="org.apache.dubbo.demo.DemoService" />
    </beans>

    加载Spring配置,并调用远程服务

    Consumer.java [3]

    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.apache.dubbo.demo.DemoService;
     
    public class Consumer {
        public static void main(String[] args) throws Exception {
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"http://10.20.160.198/wiki/display/dubbo/consumer.xml"});
            context.start();
            DemoService demoService = (DemoService)context.getBean("demoService"); // 获取远程服务代理
            String hello = demoService.sayHello("world"); // 执行远程方法
            System.out.println( hello ); // 显示调用结果
        }
    }

    。。。

    。。。。。。

    。。。。。。。。。。。。。。

    。。。。。。。。。。。。。。。。。。。。。。。。

    Dubbo原理

    框架设计

    http://dubbo.apache.org/zh-cn/docs/dev/design.html

    启动解析加载配置信息

    DubboNamespaceHandler.class   中方法 init()注册标签解析器

    service  reference 对应的为xxxBean

    解析标签的目的是为了将标签中每个属性都解析出来放入对应的XXXConfig

    容器启动 标签解析器解析每一个标签放入xxxConfig / xxxBean 中

    服务暴露

     ServerBean 在创建完对象之后调用

     

    看看他们是不是解析过了 解析过了(不为空)给他保存在ServerBean中

     在IOC容器启动完之后回调

     doExport()

    将实现类的URL等信息封装到invoker中

     

     

    服务引用

    http://dubbo.apache.org/zh-cn/docs/source_code_guide/refer-service.html

    spring的工厂bean

    init()

     

     根据注册中心地址得出注册中心的信息

     

     订阅服务

     

     

    服务调用

    http://dubbo.apache.org/zh-cn/docs/source_code_guide/service-invoking-process.html

     

  • 相关阅读:
    Mysql 免密码登录,修改密码及忘记密码操作
    CentOS 6.9 升级MySQL 5.6.36到5.7.18
    【转载】详解布隆过滤器的原理、使用场景和注意事项
    AssemblyVersion、AssemblyFileVersion、AssemblyInformationalVersion 区别
    为什么要有财务自由【转】
    CacheManager.Core
    雪花算法,生成分布式唯一ID
    监控
    什么是并行、并发, 两者的区别是什么
    Emit用法
  • 原文地址:https://www.cnblogs.com/smallores/p/13289136.html
Copyright © 2020-2023  润新知