Dubbo是什么?

Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点。
Dubbo[]是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。
其核心部分包含:

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

Dubbo能做什么?

  • 透明化的远程方法调用,就像调用本地方法一样调用远程方法,只需简单配置,没有任何API侵入。
  • 软负载均衡及容错机制,可在内网替代F5等硬件负载均衡器,降低成本,减少单点。
  • 服务自动注册与发现,不再需要写死服务提供方地址,注册中心基于接口名查询服务提供者的IP地址,并且能够平滑添加或删除服务提供者。

Spring集成

Dubbo采用全Spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spring的Schema扩展进行加载。

上面简单介绍了Dubbo的一些概念, 这里再给一张图来形象的形容下: 

我们用这张图来形容 , 那么映射到 项目中:
       当我们在多个Tomcat部署不同的系统时, 例如A系统(TomcatA)想调用B系统(TomcatB)中的服务, 这时Dubbo就有了用武之地.

       首先我们需要B系统在注册中心将自己的Url注册进去, 然后注册中心将Url返还给系统A, 那么系统A就可以调用了.
  当然了我这里说的只是Dubbo的一种用法, 在这个项目中使用的也是Dubbo的远程调用功能. (感觉真的和webservice有点像)

下面就步入正题, 看看Dubbo在项目中的使用实例:
1, 在linux下安装Zookeeper
这个地方就不详细概述Zookeeper的安装了, 前面关于Linux的博文已经有讲过在Linux下软件的安装了, 这里安装好后直接启动 Zookeeper.

2, 使用需求
在这里 当我们有一种需求, 我们需要在后台(console)去对商品(product)做一些操做, 而这里我们只能够使用到公共的service方法, 那么怎么调用product中service的实现呢? 
项目结构:

公共service方法:
TestTbService.java:

1 package cn.itcast.core.service;
2
3 import cn.itcast.core.bean.TestTb;
4
5 public interface TestTbService {
6 public void insertTestTb(TestTb testTb);
7 }


product中的service实现类:
TestTbService.java:

 1 package cn.itcast.core.service;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Service;
5 import org.springframework.transaction.annotation.Transactional;
6
7 import cn.itcast.core.bean.TestTb;
8 import cn.itcast.core.dao.TestTbDao;
9
10 @Service("testTbService")
11 @Transactional
12 public class TestTbServiceImpl implements TestTbService {
13
14 @Autowired
15 private TestTbDao testTbDao;
16
17 //保存
18 public void insertTestTb(TestTb testTb){
19 testTbDao.insertTestTb(testTb);
20 }
21 }

在console中使用product中的service实现类:
CenterController.java:

 1 package cn.itcast.core.controller;
2
3 import java.util.Date;
4
5 import org.junit.runners.model.TestTimedOutException;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Controller;
8 import org.springframework.ui.Model;
9 import org.springframework.web.bind.annotation.RequestMapping;
10
11 import cn.itcast.core.bean.TestTb;
12 import cn.itcast.core.service.TestTbService;
13
14 @Controller
15 public class CenterController {
16
17 @Autowired
18 private TestTbService testTbService;
19
20 //测试
21 @RequestMapping(value = "/test/index.do")
22 public void index(Model model){
23
24 TestTb testTb = new TestTb();
25 testTb.setName("范冰冰");
26 testTb.setBirthday(new Date());
27
28 testTbService.insertTestTb(testTb);
29
30 }
31 }

 

如果这样直接调用能够行的通吗?  当然是不行的, 在console里面定义的只是service方法, 那么这里是怎么直接调用到了product中的service实现类呢?

当然了, 这里就需要一些配置文件了:    首先是需要在product中注册服务:   dubbo-provider.xml:

 1 <beans xmlns="http://www.springframework.org/schema/beans"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
3 xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:aop="http://www.springframework.org/schema/aop"
5 xmlns:tx="http://www.springframework.org/schema/tx"
6 xmlns:task="http://www.springframework.org/schema/task"
7 xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
8 xsi:schemaLocation="http://www.springframework.org/schema/beans
9 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
10 http://www.springframework.org/schema/mvc
11 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
12 http://www.springframework.org/schema/context
13 http://www.springframework.org/schema/context/spring-context-4.0.xsd
14 http://www.springframework.org/schema/aop
15 http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
16 http://www.springframework.org/schema/tx
17 http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18 http://www.springframework.org/schema/task
19 http://www.springframework.org/schema/task/spring-task-4.0.xsd
20 http://code.alibabatech.com/schema/dubbo
21 http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22
23
24 <!-- 整合Dubbo -->
25 <!-- 第一步:Dubbo起名称 计算用此名称来区分 -->
26 <dubbo:application name="babasport-service-product"/>
27 <!-- 第二步:中介 注册中心: zookeeper redis ... -->
28 <!-- <dubbo:registry address="192.168.200.128:2181,192.168.200.129:2181,192.168.200.130:2181" protocol="zookeeper"/> -->
29 <dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/>
30 <!-- 第三步:设置dubbo的端口号 192.168.40.88:20880/接口 -->
31 <dubbo:protocol name="dubbo" port="20880"/>
32 <!-- 第四步:设置服务提供方 提供的接口 -->
33 <dubbo:service interface="cn.itcast.core.service.TestTbService" ref="testTbService"/>
34
35 </beans>

接下来就是在console中使用了:   服务消费方:    dubbo-cusmer.xml:

 1 <beans xmlns="http://www.springframework.org/schema/beans"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
3 xmlns:context="http://www.springframework.org/schema/context"
4 xmlns:aop="http://www.springframework.org/schema/aop"
5 xmlns:tx="http://www.springframework.org/schema/tx"
6 xmlns:task="http://www.springframework.org/schema/task"
7 xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
8 xsi:schemaLocation="http://www.springframework.org/schema/beans
9 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
10 http://www.springframework.org/schema/mvc
11 http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
12 http://www.springframework.org/schema/context
13 http://www.springframework.org/schema/context/spring-context-4.0.xsd
14 http://www.springframework.org/schema/aop
15 http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
16 http://www.springframework.org/schema/tx
17 http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18 http://www.springframework.org/schema/task
19 http://www.springframework.org/schema/task/spring-task-4.0.xsd
20 http://code.alibabatech.com/schema/dubbo
21 http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22
23 <!-- 整合Dubbo -->
24 <!-- 第一步:Dubbo起名称 计算用此名称来区分 -->
25 <dubbo:application name="babasport-console"/>
26 <!-- 第二步:中介 注册中心 zookeeper redis ... -->
27 <!--<dubbo:registry address="192.168.200.128:2181,192.168.200.129:2181,192.168.200.130:2181" protocol="zookeeper"/> -->
28 <dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/>
29 <!-- 第三步:调用服务提供方 提供的接口 -->
30 <dubbo:reference interface="cn.itcast.core.service.TestTbService" id="testTbService"/>
31
32 </beans>

剩下的就是启动服务了:
注意先启动服务提供方, 然后再启动服务消费方.

 

 转:https://www.cnblogs.com/wang-meng/p/5791598.html

 

Dubbo的使用及原理的更多相关文章

  1. Dubbo之服务消费原理

    前言 上篇文章<Dubbo之服务暴露>分析 Dubbo 服务是如何暴露的,本文接着分析 Dubbo 服务的消费流程.主要从以下几个方面进行分析:注册中心的暴露:通过注册中心进行服务消费通知 ...

  2. Dubbo的优雅下线原理分析

    文/朱季谦 Dubbo如何实现优雅下线? 这个问题困扰了我一阵,既然有优雅下线这种说法,那么,是否有非优雅下线的说法呢? 这,还真有. 可以从linux进程关闭说起,其实,我们经常使用到杀进程的指令背 ...

  3. Dubbo的使用及原理浅析.

    前面几个博文中关于SSM 框架已经搭建完成, 这里来讲下项目中使用到的Dubbo以及自己了解到的关于Dubbo的一些知识. Dubbo是什么? Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天 ...

  4. Dubbo架构设计及原理详解

    Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单的模 ...

  5. dubbo monitor simple 监控原理分析

    监控机制: 服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心.监控中心负责统计各服务调用次数,调用时间等. 监控元数据存储目录结构: --dubbo.jetty ...

  6. Dubbo的底层实现原理和机制

    –高性能和透明化的RPC远程服务调用方案 –SOA服务治理方案 Dubbo缺省协议采用单一长连接和NIO异步通讯, 适合于小数据量大并发的服务调用,以及服务消费者机器数远大于服务提供者机器数的情况

  7. dubbo的dispatcher设置原理

    在上回<Dubbo源代码实现六>中我们已经了解到,对于Dubbo集群中的Provider角色,有IO线程池(默认无界)和业务处理线程池(默认200)两个线程池,所以当业务的并发比较高,或者 ...

  8. Dubbo及注册中心原理

    本文首发于微信公众号[猿灯塔],转载引用请说明出处 今天是猿灯塔“365天原创计划”第4天. 今天呢!灯塔君跟大家讲: 一.Dubbo意义 网站应用的架构变化经历了一个从所有服务分布在一台服务器上(A ...

  9. alibaba远程调用框架dubbo原理

    alibaba有好几个分布式框架,主要有:进行远程调用(类似于RMI的这种远程调用)的(dubbo.hsf),jms消息服务(napoli.notify),KV数据库(tair)等.这个框架/工具/产 ...

随机推荐

  1. [COCOS2DX-LUA]0-004.cocos2dx中的DrawNode的init的方法问题

    1.诱因 近期,项目接入了Bugly, 上报了一些平常测试不出来,或者很难重现的bug,这类bug非常难排查.原因有二,第一,问题无法重现,第二,修改了无法立即验证结果.有一个问题困恼了我很久,就是一 ...

  2. Map接口之HashMap,LinkedHashMap,TreeMap

    Map与Collection 并列存在,用于保存具有映射关系的数据:Key-Value Map中的Key和Value都可以是任何引用类型的数据 Map中的Key用Set存放,不允许重复,即同一个Map ...

  3. angularjs 路由切换回到顶部

    angularjs路由切换  页面不会回到顶部 问题: 在angularjs中  ui-sref或者$state.go(),通过路由切换页面,发现新打开的路由页面仍然停留在上一次的路由页面访问的位置. ...

  4. MySql轻松入门系列————第一站 从源码角度轻松认识mysql整体框架图

    一:背景 1. 讲故事 最近看各大技术社区,不管是知乎,掘金,博客园,csdn基本上看不到有小伙伴分享sqlserver类的文章,看样子这些年sqlserver没落了,已经后继无人了,再写sqlser ...

  5. hdl - 软件编程与硬件建模

    https://mp.weixin.qq.com/s/Y75I9e3s4fDPZuv-CyiNDA   介绍软件编程思维与硬件建模思维的不同与相似之处.   ​​   1. 软件编程思维   编程,意 ...

  6. Chisel3 - Tutorial - Adder

    https://mp.weixin.qq.com/s/SEcVjGRL1YloGlEPSoHr3A   位数为参数的加法器.通过FullAdder级联实现.   参考链接: https://githu ...

  7. Java实现 蓝桥杯VIP 算法训练 无权最长链

    试题 算法训练 无权最长链 问题描述 给定一个n节点m边的无圈且连通的图,求直径 输入格式 第一行两个数字n,m 接下来m行每行两个数字x,y,代表x,y之间有一条边 输出格式 要求用户的输出满足的格 ...

  8. Java实现LeetCode 139 单词拆分

    public boolean wordBreak(String s, List<String> wordDict) { if(s.length() == 0){ return false; ...

  9. Java实现第九届蓝桥杯等腰三角形

    等腰三角形 题目描述 本题目要求你在控制台输出一个由数字组成的等腰三角形. 具体的步骤是: 1. 先用1,2,3,...的自然数拼一个足够长的串 2. 用这个串填充三角形的三条边.从上方顶点开始,逆时 ...

  10. java实现第七届蓝桥杯冰雹数

    题目8.冰雹数 题目描述 任意给定一个正整数N, 如果是偶数,执行: N / 2 如果是奇数,执行: N * 3 + 1 生成的新的数字再执行同样的动作,循环往复. 通过观察发现,这个数字会一会儿上升 ...