Dubbo开源框架学习(一)

Dubbo是 阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 Spring框架无缝集成。

Dubbo是一款高性能、轻量级的开源Java RPC框架

它提供了三大核心能力:面向接口的远程方法调用,智能容错和负载均衡,以及服务自动注册和发现。

原理图:

Registry: 服务目录框架用于服务的注册和服务事件发布和订阅;服务注册与发现的中心目录服务称之为“服务注册中心”。

Provider 暴露服务方称之为“服务提供者”。

Consumer 调用远程服务方称之为“服务消费者”。

Monitor 统计服务的调用次数和调用时间的日志服务称之为“服务监控中心”。

 

特性:(具体)

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

    提供高性能的基于代理的远程调用能力,服务以接口为粒度,为开发者屏蔽远程调用底层细节。

  • 智能负载均衡

    内置多种负载均衡策略,智能感知下游节点健康状况,显著减少调用延迟,提高系统吞吐量。

  • 服务自动注册与发现

    支持多种注册中心服务,服务实例上下线实时感知。

  • 高度可扩展能力

    遵循微内核+插件的设计原则,所有核心能力如Protocol、Transport、Serialization被设计为扩展点,平等对待内置实现和第三方实现。

  • 运行期流量调度

    内置条件、脚本等路由策略,通过配置不同的路由规则,轻松实现灰度发布,同机房优先等功能。

  • 可视化的服务治理与运维

    提供丰富服务治理、运维工具:随时查询服务元数据、服务健康状态及调用统计,实时下发路由策略、调整配置参数。

 

实例:

定义一个interface 的service

package com.alibaba.hello.api;
public interface HelloService
{
  String sayHello(String name);
}

这个接口的实现类

package com.alibaba.hello.impl;
import com.alibaba.hello.api.HelloService;
public  class  HelloServiceImpl  implements  HelloService{
    public  String  sayHello(String  name){
        return  "Hello" + name;
    }
}

Spring的配置文件

Consumer.xml

<?xmlversion="1.0"encoding="UTF-8"?>
<beans xmlns=......>
    <!--consumerapplicationname-->
    <dubbo:applicationname="consumer-of-helloworld-app"/>
    <!--registryaddress,usedforconsumertodiscoverservices-->
    <dubbo:registryaddress="multicast://224.5.6.7:1234"/>
    <!--whichservicetoconsume?-->
    <dubbo:referenceid="helloService"interface="com.alibaba.hello.api.HelloService"/>
</beans>

测试代码

Consumer.java

import  org.springframework.context.support.ClassPathXmlApplicationContext;
import  com.alibaba.hello.api.HelloService;
public  class  Consumer{
    public  static  void  main(String[]  args){
        ClassPathXmlApplicationContext  context = new  ClassPathXmlApplicationContext(newString[]{"consumer.xml"});
        HelloService  helloService = (HelloService)context.getBean("helloService");
        //getserviceinvocationproxyStringhello=helloService.sayHello("world");
        //doinvoke!System.out.println(hello);
    }
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值