Dubbo阿里巴巴内部SOA治理方案和服务的核心框架。每天2000+ 个服务提供3,000,000,000+ 次訪问量支持,并被广泛应用于阿里巴巴集团的各成员网站。Dubbo自2011年开源后,已被很多非阿里系公司使用。

Dubbo[]是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。

其核心部分包括:

  • 远程通讯: 提供对多种基于长连接的NIO框架抽象封装,包含多种线程模型。序列化。以及“请求-响应”模式的信息交换方式。
  • 集群容错: 提供基于接口方法的透明远程过程调用,包含多协议支持。以及软负载均衡,失败容错,地址路由,动态配置等集群支持。
  • 自己主动发现: 基于注冊中心文件夹服务,使服务消费方能动态的查找服务提供方,使地址透明。使服务提供方能够平滑添加或降低机器。

Dubbo能做什么?

  • 透明化的远程方法调用。就像调用本地方法一样调用远程方法,仅仅需简单配置。没有不论什么API侵入。

  • 软负载均衡及容错机制,可在内网替代F5等硬件负载均衡器,降低成本,降低单点。
  • 服务自己主动注冊与发现,不再须要写死服务提供方地址,注冊中心基于接口名查询服务提供者的IP地址,而且可以平滑加入或删除服务提供者。

高速启动

Dubbo採用全Spring配置方式。透明化接入应用,相应用没有不论什么API侵入,仅仅需用Spring载入Dubbo的配置就可以,Dubbo基于Spring的Schema扩展进行载入。
假设不想使用Spring配置。而希望通过API的方式进行调用(不推荐),请參见:API配置 (+)

服务提供者

完整安装步骤,请參见:演示样例提供者安装 (+)

定义服务接口: (该接口需单独打包,在服务提供方和消费方共享)

DemoService.java
package
com.alibaba.dubbo.demo;
 
public
interface
DemoService {
 
    String sayHello(String name);
 
}

在服务提供方实现接口:(对服务消费方隐藏实现)

DemoServiceImpl.java
package
com.alibaba.dubbo.demo.provider;
 
import
com.alibaba.dubbo.demo.DemoService;
 
public
class
DemoServiceImpl implementsDemoService {
 
    publicString sayHello(String name) {
        return"Hello "
+ name;
    }
 
}

用Spring配置声明暴露服务:

provider.xml
<?xmlversion="1.0"encoding="UTF-8"?

>

    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:applicationname="hello-world-app" />
 
    <!-- 使用multicast广播注冊中心暴露服务地址 -->
    <dubbo:registryaddress="multicast://224.5.6.7:1234"/>
 
    <!-- 用dubbo协议在20880port暴露服务 -->
    <dubbo:protocolname="dubbo"port="20880"/>
 
    <!-- 声明须要暴露的服务接口 -->
    <dubbo:serviceinterface="com.alibaba.dubbo.demo.DemoService"ref="demoService"/>
 
    <!-- 和本地bean一样实现服务 -->
    <beanid="demoService"class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/>
 
</beans>

载入Spring配置:

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

服务消费者

完整安装步骤。请參见:演示样例消费者安装 (+)

通过Spring配置引用远程服务:

consumer.xml
<?xmlversion="1.0"encoding="UTF-8"?>
    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:applicationname="consumer-of-helloworld-app" />
 
    <!-- 使用multicast广播注冊中心暴露发现服务地址 -->
    <dubbo:registryaddress="multicast://224.5.6.7:1234"/>
 
    <!-- 生成远程服务代理。能够和本地bean一样使用demoService -->
    <dubbo:referenceid="demoService"interface="com.alibaba.dubbo.demo.DemoService"/>
 
</beans>

载入Spring配置,并调用远程服务:(也能够使用IoC注入)

Consumer.java
import
org.springframework.context.support.ClassPathXmlApplicationContext;
import
com.alibaba.dubbo.demo.DemoService;
 
public
class
Consumer {
 
    publicstatic
void main(String[] args)
throws Exception {
        ClassPathXmlApplicationContext context =new
ClassPathXmlApplicationContext(newString[] {"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 系列1-Dubbo什么的更多相关文章

  1. 分布式学习系列【dubbo入门实践】

    分布式学习系列[dubbo入门实践] dubbo架构 组成部分:provider,consumer,registry,monitor: provider,consumer注册,订阅类似于消息队列的注册 ...

  2. Dubbo系列_概述

    一.本文目的         学习使用Dubbo也有一段时间了,准备写一个系列文章介绍Dubbo的相关知识和使用,供自己以后回顾和他人学习.有兴趣的同学可以加入群:74085440一起探讨 二.书写计 ...

  3. 深度学习Dubbo系列(入门开篇)

    此文档为系列学习文档 这系列文档详细讲解了dubbo的使用,基本涵盖dubbo的所有功能特性.在接下来的文章里会详细介绍. 如果你正依赖dubbo作为你业务工程的RPC通信框架,这里可以作为你的参考手 ...

  4. dubbo系列四、dubbo服务暴露过程源码解析

    一.代码准备 1.示例代码 参考dubbo系列二.dubbo+zookeeper+dubboadmin分布式服务框架搭建(windows平台) 2.简单了解下spring自定义标签 https://w ...

  5. Dubbo 系列(05-1)服务发布

    目录 Dubbo 系列(05-1)服务发布 Spring Cloud Alibaba 系列目录 - Dubbo 篇 1. 背景介绍 1.1 服务暴露整体机制 2. 源码分析 2.1 前置工作 2.2 ...

  6. Dubbo 系列(07-5)集群容错 - Mock

    Dubbo 系列(07-5)集群容错 - Mock [toc] Spring Cloud Alibaba 系列目录 - Dubbo 篇 1. 背景介绍 相关文档推荐: Dubbo 实战 - 服务降级 ...

  7. Dubbo 系列(07-4)集群容错 - 集群

    BDubbo 系列(07-4)集群容错 - 集群 [toc] Spring Cloud Alibaba 系列目录 - Dubbo 篇 1. 背景介绍 相关文档推荐: Dubbo 集群容错 - 实战 D ...

  8. Dubbo 系列(07-3)集群容错 - 负载均衡

    目录 Dubbo 系列(07-3)集群容错 - 负载均衡 Spring Cloud Alibaba 系列目录 - Dubbo 篇 1. 背景介绍 1.1 负载均衡算法 1.2 继承体系 2. 源码分析 ...

  9. Dubbo 系列(07-2)集群容错 - 服务路由

    目录 Dubbo 系列(07-2)集群容错 - 服务路由 1. 背景介绍 1.1 继承体系 1.2 SPI 2. 源码分析 2.1 创建路由规则 2.2 RouteChain 2.3 条件路由 Dub ...

随机推荐

  1. CentOS7+Tomcat 生产系统部署

    1 准备OS账户 安全起见,本着最小权限原则,生产系统决不同意使用root账户来执行tomcat.为此,建立新账户tomcat,并设定登录password. useradd tomcat passwd ...

  2. OpenMp高速分拣

    #include <stdio.h> #include<stdafx.h> #include<iostream> #include <stdlib.h> ...

  3. FusionCharts简单教程---建立第一个FusionCharts图形

    由于项目需求需要做一个报表,选择FusionCharts作为工具使用.由于以前没有接触过报表,网上也没有比较详细的fusionCharts教程,所以决定好好研究FusionCharts,同时做一个比较 ...

  4. HDU 1394 Minimum Inversion Number (数据结构-段树)

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  5. 学派Delphi方法(推荐)——————————【Badboy】

    Delphi是一个新的可视化编程环境, 提供了一种方便.快捷的Windows使用顺序开发工具. 它使用了MicrosoftWindows图形用户界面的很多先进特性和设计思想. 本文就给读者引见学Del ...

  6. Nginx+Varnish

    Nginx+Varnish 实现动静分离,为服务器分流,降低服务器负载 相必大家在看加快网站响应速度方面的文章时,都提过这么一条:动静分离.那怎样实现动静分离呢,这里笔者就亲自搭建相关服务实现动静分离 ...

  7. 动态Lambda进阶一

    直接上代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...

  8. 最佳新秀SSH十六Struts2它是如何工作的内部

    前面说完了Spring.Hibernate,非常自然今天轮到struts了.struts的核心原理就是通过拦截器来处理client的请求,经过拦截器一系列的处理后,再交给Action.以下先看看str ...

  9. CSAPP 六个重要的实验 lab5

    CSAPP  && lab5 实验指导书: http://download.csdn.net/detail/u011368821/7951657 实验材料: http://downlo ...

  10. cocos2d-x路~使得第一个字游戏(一个)

    前言 去年的回忆.另外,在第三.他们开发了他们的第一场比赛四月,它是游戏.所以我决定走上独立开发的道路上.了.第一款游戏达到它应有的盈利水平.然而这款游戏开发后的时间里.都没再取得还有一款令自己惬意的 ...