环境搭建的步骤有哪些

  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. C++ 提取网页内容系列之五 整合爬取豆瓣读书

    工作太忙 没有时间细化了 就说说 主要内容吧 下载和分析漫画是分开的 下载豆瓣漫画页面是使用之前的文章的代码 见http://www.cnblogs.com/itdef/p/4171179.html ...

  2. 【机器学习】Octave 实现逻辑回归 Logistic Regression

    ex2data1.txt ex2data2.txt 本次算法的背景是,假如你是一个大学的管理者,你需要根据学生之前的成绩(两门科目)来预测该学生是否能进入该大学. 根据题意,我们不难分辨出这是一种二分 ...

  3. springboot 使用maven 打包 报 (请使用 -source 7 或更高版本以启用 diamond 运算符) 错误解决办法

    在使用springboot maven 打包时 报如下错误 (请使用 -source 7 或更高版本以启用 diamond 运算符) pom.xml编译插件 配置如下: <plugin> ...

  4. 20155339 Exp9 Web安全基础

    Exp9 Web安全基础 基础问题回答 (1)SQL注入攻击原理,如何防御 原理:它是利用现有应用程序,将恶意的SQL命令注入到后台数据库引擎执行的能力,它可以通过在Web表单中输入恶意SQL语句得到 ...

  5. 2019swpuj2ee作业一:C/S,B/S的应用的区别

    1.硬件环境不同: C/S 一般建立在专用的网络上, 小范围里的网络环境, 局域网之间再通过专门服务器提供连接和数据交换服务.B/S 建立在广域网之上的, 不必是专门的网络硬件环境,例与电话上网,  ...

  6. Maths | 二次型求偏导

  7. OpenCV2.4.10 + VS2010开发环境配置

    原文转载自:qinyang8513 一.开发环境 1.操作系统:Windows 7(64位) 2.编程环境:Microsoft Visual Studio 2010 3.OpenCV版本:2.4.10 ...

  8. 【repost】学JS必看-JavaScript数据结构深度剖析

    JavaScript以其强大灵活的特点,被广泛运用于各种类型的网站上.一直以来都没怎么好好学JS,只是略懂皮毛,看这篇文章时有读<PHP圣经>的感觉,作者深入浅出.生动形象地用各种实例给我 ...

  9. a标签使用href=”javascript:void(0); 在火狐浏览器跟chrome 不兼容

    使用如下方式的链接.在Chrome中点击后行为符合预期,但在IE下会新开标签卡(根据参考资料,Firefox中有相同问题).<a href=”javascript:void(0);” targe ...

  10. Centos7.0进入单用户模式修改root密码

    启动Centos7 ,按空格让其停留在如下界面. 按e进行编辑 在UTF-8后面输入init=/bin/sh 根据提示按ctrl+x 得如下图 输入mount -o remount,rw /  然后输 ...