1.从github上clone下duboo的源码并checkout tag到2.6.5可以看到如下的结构:

其中all-dubbo的pom如下:

这里会将dubbo的其他项目在package的时候打到一个包里,注意到这里依赖的其他模块全部都是optional,在只依赖dubbo时其他子模块是不会被依赖传递的,这也意味了子模块的依赖也不会传递,不注意这一点的话,在调试的时候很容易奇怪为什么相应的依赖没有传递下去。

3.mvn clean install -Dmaven.test.skip=true进行构建得到本地仓库下com.alibaba.*:

4.新建一个项目依赖dubbo,resource下配置好log4j和dubbo的配置文件:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
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"> <!-- provider's application name, used for tracing dependency relationship -->
<dubbo:application name="echo-provider"/>
<!-- use multicast registry center to export service -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- use dubbo protocol to export service on port 20880 -->
<dubbo:protocol name="dubbo" port="20880"/>
<!-- service implementation, as same as regular local bean -->
<bean id="echoService" class="provider.EchoServiceImpl"/>
<!-- declare the service interface to be exported -->
<dubbo:service interface="facade.EchoService" ref="echoService"/>
</beans>

5.用spring的方式写一个provider:

import facade.EchoService;
import com.alibaba.dubbo.rpc.RpcContext;
import java.text.SimpleDateFormat;
import java.util.Date; public class EchoServiceImpl implements EchoService {
public String echo(String message) {
String now=new SimpleDateFormat("HH:mm:ss").format(new Date());
System.out.println("["+now+"] Hello"+message+", request from consumer"+RpcContext.getContext().getRemoteAddressString());
return message;
}
}

6.启动zk集群。

7.start Spring容器,可以看到/dubbo/facade.EchoService/providers下的节点(/root/service/[provider,consumer,routers,confugurators]):(临时节点)

8.同样新建一个conusmer,并start:

import facade.EchoService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.IOException; public class EchoConsumer {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext(new String[]{"spring/echo-api.xml"});
context.start();
EchoService echoService=(EchoService)context.getBean("echoService");
String status=echoService.echo("hello word");
System.out.println("echo result:"+status);
System.in.read();
}
}
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns="http://www.springframework.org/schema/beans"
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"> <!-- provider's application name, used for tracing dependency relationship -->
<dubbo:application name="echo-api"/>
<!-- use multicast registry center to export service -->
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!-- use dubbo protocol to export service on port 20880 --> <!-- declare the service interface to be exported -->
<dubbo:reference id="echoService" check="false" interface="facade.EchoService"/>
</beans>

dubbo源码调试的更多相关文章

  1. Dubbo源码-Dubbo是如何随心所欲自定义XML标签的

    叨叨 今天考虑了很久要不要写这篇文章. 距离<Dubbo源码>系列的开篇到现在已经快两个月时间了.当时是想着工作上的RPC框架使用存在一些让人头疼的问题,就来看看Dubbo给出了一套什么样 ...

  2. Dubbo 源码分析 - 集群容错之 LoadBalance

    1.简介 LoadBalance 中文意思为负载均衡,它的职责是将网络请求,或者其他形式的负载"均摊"到不同的机器上.避免集群中部分服务器压力过大,而另一些服务器比较空闲的情况.通 ...

  3. Dubbo 源码分析 - 集群容错之 Router

    1. 简介 上一篇文章分析了集群容错的第一部分 -- 服务目录 Directory.服务目录在刷新 Invoker 列表的过程中,会通过 Router 进行服务路由.上一篇文章关于服务路由相关逻辑没有 ...

  4. Dubbo 源码分析 - 服务导出

    1.服务导出过程 本篇文章,我们来研究一下 Dubbo 导出服务的过程.Dubbo 服务导出过程始于 Spring 容器发布刷新事件,Dubbo 在接收到事件后,会立即执行服务导出逻辑.整个逻辑大致可 ...

  5. Dubbo 源码分析 - 自适应拓展原理

    1.原理 我在上一篇文章中分析了 Dubbo 的 SPI 机制,Dubbo SPI 是 Dubbo 框架的核心.Dubbo 中的很多拓展都是通过 SPI 机制进行加载的,比如 Protocol.Clu ...

  6. 【Dubbo源码阅读系列】之远程服务调用(上)

    今天打算来讲一讲 Dubbo 服务远程调用.笔者在开始看 Dubbo 远程服务相关源码的时候,看的有点迷糊.后来慢慢明白 Dubbo 远程服务的调用的本质就是动态代理模式的一种实现.本地消费者无须知道 ...

  7. Dubbo(三):深入理解Dubbo源码之如何将服务发布到注册中心

    一.前言 前面有说到Dubbo的服务发现机制,也就是SPI,那既然Dubbo内部实现了更加强大的服务发现机制,现在我们就来一起看看Dubbo在发现服务后需要做什么才能将服务注册到注册中心中. 二.Du ...

  8. 【2020-03-28】Dubbo源码杂谈

    前言 本周空闲时间利用了百分之六七十的样子.主要将Dubbo官网文档和本地代码debug结合起来学习,基本看完了服务导出.服务引入以及服务调用的过程,暂未涉及路由.字典等功能.下面对这一周的收获进行一 ...

  9. Dubbo源码剖析三之服务注册过程分析

    Dubbo源码剖析二之注册中心 - 池塘里洗澡的鸭子 - 博客园 (cnblogs.com)中对注册中心进行了简单的介绍,对Dubbo整合Zookeeper链接源码进行了详细分析.本文接着对服务注册过 ...

随机推荐

  1. ModelSerializer 高级使用

    前言 ModelSerializer中还具有一些高级用法,如批量更新.批量删除.批量创建等. 但是批量过来的数据格式都需要与前端做好协商,什么样的数据格式是单条操作,什么样的数据格式是批量操作. 如下 ...

  2. Spring中的BeanFactory与FactoryBean看这一篇就够了

    前言 理解FactoryBean是非常非常有必要的,因为在Spring中FactoryBean最为典型的一个应用就是用来创建AOP的代理对象,不仅如此,而且对理解Mybatis核心源码也非常有帮助!如 ...

  3. python爬虫使用scrapy框架

    scrapy框架提升篇 关注公众号"轻松学编程"了解更多 1.创建启动爬虫脚本 在项目目录下创建start.py文件: 添加代码: #以后只要运行start.py就可以启动爬虫 i ...

  4. Python爬虫之线程池

    详情点我跳转 关注公众号"轻松学编程"了解更多. 一.为什么要使用线程池? 对于任务数量不断增加的程序,每有一个任务就生成一个线程,最终会导致线程数量的失控,例如,整站爬虫,假设初 ...

  5. python数据类型之dict(字典)

    dict字典 关注公众号"轻松学编程"了解更多. 1.概述 dict也是一种存储方式,类似于list和tuple,但是,字典采用键-值(key-value)的形式存储. 优点:具有 ...

  6. Mybatis之plugin插件设计原理

    大多数框架,都支持插件,用户可通过编写插件来自行扩展功能,Mybatis也不例外. 我们从插件配置.插件编写.插件运行原理.插件注册与执行拦截的时机.初始化插件.分页插件的原理等六个方面展开阐述. 一 ...

  7. 【Kata Daily 190908】How Much?

    原题: I always thought that my old friend John was rather richer than he looked, but I never knew exac ...

  8. OJ-2:区间问题【九度1554】

      题目描述: 给定一个数组,判断数组内是否存在一个连续区间,使其和恰好等于给定整数k. 输入: 输入包含多组测试用例,每组测试用例由一个整数n(1<=n<=10000)开头,代表数组的大 ...

  9. leetcode 38:path-sum

    题目描述 给定一个二叉树和一个值sum,判断是否有从根节点到叶子节点的节点值之和等于sum的路径, 例如: 给出如下的二叉树,sum=22,              5              / ...

  10. 【老孟Flutter】6种极大提升Flutter开发效率的工具包

    老孟导读:本文介绍6种极大提升Flutter开发效率的工具包. [1] 强大的日志软件包 在开发 Flutter 的过程中打印日志是常用的调试方式之一,但 Flutter 内置的日志打印非常简单,下面 ...