环境搭建的步骤有哪些

  1. 依赖外部的环境
  2. 使用的开发工具
  3. 源码的拉取
  4. 结构大致介绍

1 依赖的外部环境

  • 安装JDK
  • 安装Git
  • 安装maven

这边我们就不介绍怎么安装这些外部环境了,大家自行从安装这些外部环境哈

2 使用的外部工具

  • 编辑器使用 IntelliJ IDEA (简单好用,快捷键丰富)
  • GitHub Desktop GitHub的客户端软件,用起来真顺手

3 源码的拉取

源码的话我们上GitHub 上面直接拉取dubbo的源码即可, Dubbo 然后我们 Fork出一个属于我们自己的仓库,之后我们就可以在我们GitHub的仓库中看到这个项目了。然后我们将这个项目down到本地进行调试

具体Git操作不详细介绍,下面贴出几个比较好的供大家参考

https://blog.csdn.net/qq_32040767/article/details/77096761

https://blog.csdn.net/menggudaoke/article/details/77744541

https://juejin.im/entry/5a5f3b286fb9a01c9064e83b

https://www.cnblogs.com/MrJun/p/3351478.html

这里我们为什么使用Fork 而不是Star,这是因为star的项目你不是Pull Request 到源项目的,而Fork 是可以的。想想一下要是你在看源码的过程中发现了bug。然后提交给他们并审核这是一件多酷的事情

4 Dubbo的大致介绍

下面的这个 Dubbo 官网上最为经典的介绍,一张图就将整个Dubbo 过程大致的介绍的差不多。

什么是Dubbo?

一个分布式服务治理框架

Dubbo的作用是什么?

作用是解决下面的问题

  • 单一应用架构

  • 垂直应用架构

  • 分布式服务架构

  • 流动计算架构

节点角色说明

节点 角色说明
Provider 暴露服务的服务提供方
Consumer 调用远程服务的服务消费方
Registry 服务注册与发现的注册中心
Monitor 统计服务的调用次数和调用时间的监控中心
Container 服务运行容器

调用关系说明

  1. 服务容器负责启动,加载,运行服务提供者。

  2. 服务容器负责启动,加载,运行服务提供者。
  3. 服务提供者在启动时,向注册中心注册自己提供的服务。
  4. 服务消费者在启动时,向注册中心订阅自己所需的服务。
  5. 注册中心返回服务提供者地址列表给消费者,如果有变更,注册中心将基于长连接推送变更数据给消费者。
  6. 服务消费者,从提供者地址列表中,基于软负载均衡算法,选一台提供者进行调用,如果调用失败,再选另一台调用。
  7. 服务消费者和提供者,在内存中累计调用次数和调用时间,定时每分钟发送一次统计数据到监控中心。

详细介绍下 Registry Provider Consumer

因为这三者是整个Dubbo 调用过程的链路核心

talk is cheap show me the code

光说不行,咱们通过看下项目中的源码来看下dubbo整个结构

dubbo提供了 一个demo项目供大家测试调试 整个demo已经在你down的dubbo的项目中了

打开我们的dubbo项目,我们会看到这样的一个子项目

这里就是那个demo子项目 就是我们可以直接运行测试的项目

将整个测试项目展开,我们会看见这几个文件

我们先进入consumer项目中的 Consumer类中,运行这个类。在这里是一个main函数,我们直接运行就ok了

之后我们再启动Provider 类。这样的话,我们就启动了一对消费者和生产类。这样的话,最简单的dubbo程序就 启动了。

下面我们根据这个最简单的类来分析下

package org.apache.dubbo.demo;
// 服务对外暴露接口
public interface DemoService { String sayHello(String name); }
package org.apache.dubbo.demo.consumer;

import org.apache.dubbo.demo.DemoService;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Consumer { /**
* To get ipv6 address to work, add
* System.setProperty("java.net.preferIPv6Addresses", "true");
* before running your application.
*/
public static void main(String[] args) {
//加载配置的xml文件
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-consumer.xml"});
context.start();
//从这个上下文bean中获取类
DemoService demoService = (DemoService) context.getBean("demoService"); // get remote service proxy
while (true) {
try {
Thread.sleep(1000);
String hello = demoService.sayHello("world"); // call remote method
System.out.println(hello); // get result
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
}

消费者的测试demo,循环调用方法

<?xml version="1.0" encoding="UTF-8"?>
<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"> <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
don't set it same as provider -->
<dubbo:application name="demo-consumer"/> <!-- use multicast registry center to discover service -->
<!-- 测试的时候使用组播来进行注册发现 -->
<dubbo:registry address="multicast://224.5.6.7:1234"/> <!-- generate proxy for the remote service, then demoService can be used in the same way as the
local regular interface -->
<!--生成一个代理,在这个方法调用远程方法就像调用本地方法一样 -->
<dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/> </beans>

我们通过配置文件xml来进行服务的发现和启用,还有对注册中心的配置

下面介绍下服务的提供者Provider

package org.apache.dubbo.demo.provider;

import org.apache.dubbo.demo.DemoService;
import org.apache.dubbo.rpc.RpcContext; import java.text.SimpleDateFormat;
import java.util.Date; public class DemoServiceImpl implements DemoService { @Override
public String sayHello(String name) {
//对外暴露的服务内部实现类
System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
} }
package org.apache.dubbo.demo.provider;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Provider {

    /** * To get ipv6 address to work, add * System.setProperty("java.net.preferIPv6Addresses", "true"); * before running your application. */
public static void main(String[] args) throws Exception {
//加载xml配置
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-provider.xml"});
context.start();
System.in.read(); // press any key to exit
}
}
<?xml version="1.0" encoding="UTF-8"?>

    <!-- provider's application name, used for tracing dependency relationship -->
<!-- 提供一个应用名称,用于查找依赖的关系-->
<dubbo:application name="demo-provider"/> <!-- use multicast registry center to export service -->
<!-- 使用组播来进行服务的暴露-->
<dubbo:registry address="multicast://224.5.6.7:1234"/> <!-- use dubbo protocol to export service on port 20880 -->
<!-- 使用dubbo协议对外暴露时的端口-->
<dubbo:protocol name="dubbo" port="20880"/> <!-- service implementation, as same as regular local bean -->
<!-- 业务实现类,对外暴露类的内部实现-->
<bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/> <!-- declare the service interface to be exported -->
<!-- 对外暴露服务的接口 -->
<dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService"/> </beans>

博客园展示效果不好,可以移步到GitHub 博客上

http://wsccoder.top/2018/09/14/Dubbo-%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E7%B3%BB%E5%88%97%E4%B9%8B%E4%B8%80%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/

Dubbo 源码分析系列之一环境搭建的更多相关文章

  1. mybatis源码分析之01环境搭建

    直接使用maven搭建一个mybatis的运行环境 1. pom.xml <?xml version="1.0" encoding="UTF-8"?> ...

  2. Dubbo源码分析系列---服务的发布

    摘要: 通过解析配置文件,将xml定义的Bean解析并实例化,(涉及重要的类:ServiceBean.RegistryConfig[注册中心配置].ProtocolConfig[协议配置].Appli ...

  3. Dubbo源码分析系列---扩展点加载

    扩展点配置: 约定: 在扩展类的jar包内,放置扩展点配置文件:META-INF/dubbo/接口全限定名,内容为:配置名=扩展实现类全限定名,多个实现类用换行符分隔.(摘自dubbo文档) 示例: ...

  4. [ethereum源码分析](1) dubug环境搭建

    前言 因为最近云小哥哥换了一份工作,新公司比较忙,所以一直没有更新新的博客.云小哥哥新的公司是做区块链的,最近在学习区块链相关的东西(也算是乘坐上了区块链这艘大船).本博客是记录我搭建ethereum ...

  5. Dubbo 源码分析系列之三 —— 架构原理

    1 核心功能 首先要了解Dubbo提供的三大核心功能: Remoting:远程通讯 提供对多种NIO框架抽象封装,包括"同步转异步"和"请求-响应"模式的信息交 ...

  6. Dubbo 源码分析 - 集群容错之 Cluster

    1.简介 为了避免单点故障,现在的应用至少会部署在两台服务器上.对于一些负载比较高的服务,会部署更多台服务器.这样,同一环境下的服务提供者数量会大于1.对于服务消费者来说,同一环境下出现了多个服务提供 ...

  7. Dubbo 源码分析 - 服务调用过程

    注: 本系列文章已捐赠给 Dubbo 社区,你也可以在 Dubbo 官方文档中阅读本系列文章. 1. 简介 在前面的文章中,我们分析了 Dubbo SPI.服务导出与引入.以及集群容错方面的代码.经过 ...

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

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

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

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

随机推荐

  1. AutoCAD开发2--添加带属性的点

    Private Sub CommandButton11_Click() Dim pPoint As AcadPoint Dim DataType(0 To 1) As Integer Dim Data ...

  2. SPOJ - AMR11B

    题目链接:https://www.spoj.com/problems/AMR11B/en/ 题目大意就是要你求图形覆盖的格点数,标记每个图形里的未标记格点(包括边界),总标记数就是覆盖的总格点数. # ...

  3. Spring 的配置详解

    Bean元素 Spring创建对象的方式 (1)空参构造方式 (2)静态工厂(了解) (3)实例工厂方式 Bean元素进阶 (1)scope属性 a.singleton (2)生命周期属性 Sprin ...

  4. s11.9 sar:收集系统信息

    功能说明: 通过sar命令,可以全面地获取系统的CPU.运行队列.磁盘I/O.分页(交换区).内存.CPU中断和网络等性能数据. 语法格式 sar  option interval count sar ...

  5. ModelAndView对象

    ModelAndView属性中两个最重要的属性是model和view. view即视图,保存的是视图信息. model即模型,以<K,V>形式保存模型数据,上图可以看到是MdelMap类型 ...

  6. 利用蒙特卡洛(Monte Carlo)方法计算π值[ 转载]

    部分转载自:https://blog.csdn.net/daniel960601/article/details/79121055 圆周率π是一个无理数,没有任何一个精确公式能够计算π值,π的计算只能 ...

  7. nginx 502 bad gateway 问题处理集锦

    一般看来, 这种情况可能是由于nginx默认的fastcgi进程响应的缓冲区太小造成的, 这将导致fastcgi进程被挂起, 如果你的fastcgi服务对这个挂起处理的不好, 那么最后就极有可能导致5 ...

  8. JS应用实例3:定时弹出广告

    在观看视频时候总会发现有广告弹出 这里就做一个类似这样的定时弹出广告的实例: 前面的JS代码和HTML写在同一个文件,实际开发中总是分开来写 用的时候引入即可 HTML代码: <!DOCTYPE ...

  9. Shell-11--for

    $(cat /etc/passwd) `cat /etc/passwd`

  10. kubernetes集群搭建(1):环境准备

    了解kubernets 本次搭建采用的是1个master节点,2个node节点,一个私有docker仓库 1.设置各节点ip信息 2.设置hostname(其它节点也需修改) vi /etc/sysc ...