<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>入门介绍 on Apache Dubbo</title><link>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/</link><description>Recent content in 入门介绍 on Apache Dubbo</description><generator>Hugo</generator><language>zh-cn</language><atom:link href="https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/index.xml" rel="self" type="application/rss+xml"/><item><title>背景</title><link>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/background/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/background/</guid><description>&lt;p>随着互联网的发展，网站应用的规模不断扩大，常规的垂直应用架构已无法应对，分布式服务架构以及流动计算架构势在必行，亟需一个治理系统确保架构有条不紊的演进。&lt;/p>
&lt;p>&lt;img alt="image" src="https://deploy-preview-3202--dubbo.netlify.app/imgs/user/dubbo-architecture-roadmap.jpg">&lt;/p>
&lt;h3 id="单一应用架构">单一应用架构&lt;/h3>
&lt;p>当网站流量很小时，只需一个应用，将所有功能都部署在一起，以减少部署节点和成本。此时，用于简化增删改查工作量的数据访问框架(ORM)是关键。&lt;/p>
&lt;h3 id="垂直应用架构">垂直应用架构&lt;/h3>
&lt;p>当访问量逐渐增大，单一应用增加机器带来的加速度越来越小，提升效率的方法之一是将应用拆成互不相干的几个应用，以提升效率。此时，用于加速前端页面开发的Web框架(MVC)是关键。&lt;/p>
&lt;h3 id="分布式服务架构">分布式服务架构&lt;/h3>
&lt;p>当垂直应用越来越多，应用之间交互不可避免，将核心业务抽取出来，作为独立的服务，逐渐形成稳定的服务中心，使前端应用能更快速的响应多变的市场需求。此时，用于提高业务复用及整合的分布式服务框架(RPC)是关键。&lt;/p>
&lt;h3 id="流动计算架构">流动计算架构&lt;/h3>
&lt;p>当服务越来越多，容量的评估，小服务资源的浪费等问题逐渐显现，此时需增加一个调度中心基于访问压力实时管理集群容量，提高集群利用率。此时，用于提高机器利用率的资源调度和治理中心(SOA)是关键。&lt;/p></description></item><item><title>需求</title><link>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/requirements/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/requirements/</guid><description>&lt;p>&lt;img alt="image" src="https://deploy-preview-3202--dubbo.netlify.app/imgs/user/dubbo-service-governance.jpg">&lt;/p>
&lt;p>在大规模服务化之前，应用可能只是通过 RMI 或 Hessian 等工具，简单的暴露和引用远程服务，通过配置服务的URL地址进行调用，通过 F5 等硬件进行负载均衡。&lt;/p>
&lt;h3 id="服务配置">服务配置&lt;/h3>
&lt;p>&lt;strong>当服务越来越多时，服务 URL 配置管理变得非常困难，F5 硬件负载均衡器的单点压力也越来越大。&lt;/strong> 此时需要一个服务注册中心，动态地注册和发现服务，使服务的位置透明。并通过在消费方获取服务提供方地址列表，实现软负载均衡和 Failover，降低对 F5 硬件负载均衡器的依赖，也能减少部分成本。&lt;/p>
&lt;h3 id="服务依赖">服务依赖&lt;/h3>
&lt;p>&lt;strong>当进一步发展，服务间依赖关系变得错踪复杂，甚至分不清哪个应用要在哪个应用之前启动，架构师都不能完整的描述应用的架构关系。&lt;/strong> 这时，需要自动画出应用间的依赖关系图，以帮助架构师理清关系。&lt;/p>
&lt;h3 id="服务容量">服务容量&lt;/h3>
&lt;p>&lt;strong>接着，服务的调用量越来越大，服务的容量问题就暴露出来，这个服务需要多少机器支撑？什么时候该加机器？&lt;/strong> 为了解决这些问题，第一步，要将服务现在每天的调用量，响应时间，都统计出来，作为容量规划的参考指标。其次，要可以动态调整权重，在线上，将某台机器的权重一直加大，并在加大的过程中记录响应时间的变化，直到响应时间到达阈值，记录此时的访问量，再以此访问量乘以机器数反推总容量。&lt;/p>
&lt;p>以上是 Dubbo 最基本的几个需求。&lt;/p></description></item><item><title>架构</title><link>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/architecture/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/architecture/</guid><description>&lt;p>&lt;img alt="dubbo-architucture" src="https://deploy-preview-3202--dubbo.netlify.app/imgs/user/dubbo-architecture.jpg">&lt;/p>
&lt;h3 id="节点角色说明">节点角色说明&lt;/h3>
&lt;table>
 &lt;thead>
 &lt;tr>
 &lt;th style="text-align: left">节点&lt;/th>
 &lt;th style="text-align: left">角色说明&lt;/th>
 &lt;/tr>
 &lt;/thead>
 &lt;tbody>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Provider&lt;/code>&lt;/td>
 &lt;td style="text-align: left">暴露服务的服务提供方&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Consumer&lt;/code>&lt;/td>
 &lt;td style="text-align: left">调用远程服务的服务消费方&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Registry&lt;/code>&lt;/td>
 &lt;td style="text-align: left">服务注册与发现的注册中心&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Monitor&lt;/code>&lt;/td>
 &lt;td style="text-align: left">统计服务的调用次数和调用时间的监控中心&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Container&lt;/code>&lt;/td>
 &lt;td style="text-align: left">服务运行容器&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table>
&lt;h3 id="调用关系说明">调用关系说明&lt;/h3>
&lt;ol start="0">
&lt;li>服务容器负责启动，加载，运行服务提供者。&lt;/li>
&lt;li>服务提供者在启动时，向注册中心注册自己提供的服务。&lt;/li>
&lt;li>服务消费者在启动时，向注册中心订阅自己所需的服务。&lt;/li>
&lt;li>注册中心返回服务提供者地址列表给消费者，如果有变更，注册中心将基于长连接推送变更数据给消费者。&lt;/li>
&lt;li>服务消费者，从提供者地址列表中，基于软负载均衡算法，选一台提供者进行调用，如果调用失败，再选另一台调用。&lt;/li>
&lt;li>服务消费者和提供者，在内存中累计调用次数和调用时间，定时每分钟发送一次统计数据到监控中心。&lt;/li>
&lt;/ol>
&lt;p>Dubbo 架构具有以下几个特点，分别是连通性、健壮性、伸缩性、以及向未来架构的升级性。&lt;/p>
&lt;h3 id="连通性">连通性&lt;/h3>
&lt;ul>
&lt;li>注册中心负责服务地址的注册与查找，相当于目录服务，服务提供者和消费者只在启动时与注册中心交互，注册中心不转发请求，压力较小&lt;/li>
&lt;li>监控中心负责统计各服务调用次数，调用时间等，统计先在内存汇总后每分钟一次发送到监控中心服务器，并以报表展示&lt;/li>
&lt;li>服务提供者向注册中心注册其提供的服务，并汇报调用时间到监控中心，此时间不包含网络开销&lt;/li>
&lt;li>服务消费者向注册中心获取服务提供者地址列表，并根据负载算法直接调用提供者，同时汇报调用时间到监控中心，此时间包含网络开销&lt;/li>
&lt;li>注册中心，服务提供者，服务消费者三者之间均为长连接，监控中心除外&lt;/li>
&lt;li>注册中心通过长连接感知服务提供者的存在，服务提供者宕机，注册中心将立即推送事件通知消费者&lt;/li>
&lt;li>注册中心和监控中心全部宕机，不影响已运行的提供者和消费者，消费者在本地缓存了提供者列表&lt;/li>
&lt;li>注册中心和监控中心都是可选的，服务消费者可以直连服务提供者&lt;/li>
&lt;/ul>
&lt;h3 id="健壮性">健壮性&lt;/h3>
&lt;ul>
&lt;li>监控中心宕掉不影响使用，只是丢失部分采样数据&lt;/li>
&lt;li>数据库宕掉后，注册中心仍能通过缓存提供服务列表查询，但不能注册新服务&lt;/li>
&lt;li>注册中心对等集群，任意一台宕掉后，将自动切换到另一台&lt;/li>
&lt;li>注册中心全部宕掉后，服务提供者和服务消费者仍能通过本地缓存通讯&lt;/li>
&lt;li>服务提供者无状态，任意一台宕掉后，不影响使用&lt;/li>
&lt;li>服务提供者全部宕掉后，服务消费者应用将无法使用，并无限次重连等待服务提供者恢复&lt;/li>
&lt;/ul>
&lt;h3 id="伸缩性">伸缩性&lt;/h3>
&lt;ul>
&lt;li>注册中心为对等集群，可动态增加机器部署实例，所有客户端将自动发现新的注册中心&lt;/li>
&lt;li>服务提供者无状态，可动态增加机器部署实例，注册中心将推送新的服务提供者信息给消费者&lt;/li>
&lt;/ul>
&lt;h3 id="升级性">升级性&lt;/h3>
&lt;p>当服务集群规模进一步扩大，带动IT治理结构进一步升级，需要实现动态部署，进行流动计算，现有分布式服务架构不会带来阻力。下图是未来可能的一种架构：&lt;/p>
&lt;p>&lt;img alt="dubbo-architucture-futures" src="https://deploy-preview-3202--dubbo.netlify.app/imgs/user/dubbo-architecture-future.jpg">&lt;/p>
&lt;h5 id="节点角色说明-1">节点角色说明&lt;/h5>
&lt;table>
 &lt;thead>
 &lt;tr>
 &lt;th style="text-align: left">节点&lt;/th>
 &lt;th style="text-align: left">角色说明&lt;/th>
 &lt;/tr>
 &lt;/thead>
 &lt;tbody>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Deployer &lt;/code>&lt;/td>
 &lt;td style="text-align: left">自动部署服务的本地代理&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Repository&lt;/code>&lt;/td>
 &lt;td style="text-align: left">仓库用于存储服务应用发布包&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Scheduler&lt;/code>&lt;/td>
 &lt;td style="text-align: left">调度中心基于访问压力自动增减服务提供者&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Admin&lt;/code>&lt;/td>
 &lt;td style="text-align: left">统一管理控制台&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Registry&lt;/code>&lt;/td>
 &lt;td style="text-align: left">服务注册与发现的注册中心&lt;/td>
 &lt;/tr>
 &lt;tr>
 &lt;td style="text-align: left">&lt;code>Monitor&lt;/code>&lt;/td>
 &lt;td style="text-align: left">统计服务的调用次数和调用时间的监控中心&lt;/td>
 &lt;/tr>
 &lt;/tbody>
&lt;/table></description></item><item><title>用法</title><link>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/usage/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3202--dubbo.netlify.app/zh-cn/docsv2.7/user/preface/usage/</guid><description>&lt;h3 id="本地服务-spring-配置">本地服务 Spring 配置&lt;/h3>
&lt;p>&lt;code>local.xml&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-xml" data-lang="xml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;bean&lt;/span> id=&lt;span style="color:#2aa198">“xxxService”&lt;/span> class=&lt;span style="color:#2aa198">“com.xxx.XxxServiceImpl”&lt;/span> &lt;span style="color:#268bd2">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;bean&lt;/span> id=&lt;span style="color:#2aa198">“xxxAction”&lt;/span> class=&lt;span style="color:#2aa198">“com.xxx.XxxAction”&lt;/span>&lt;span style="color:#268bd2">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#268bd2">&amp;lt;property&lt;/span> name=&lt;span style="color:#2aa198">“xxxService”&lt;/span> ref=&lt;span style="color:#2aa198">“xxxService”&lt;/span> &lt;span style="color:#268bd2">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;/bean&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="远程服务-spring-配置">远程服务 Spring 配置&lt;/h3>
&lt;p>在本地服务的基础上，只需做简单配置，即可完成远程化：&lt;/p>
&lt;ul>
&lt;li>将上面的 &lt;code>local.xml&lt;/code> 配置拆分成两份，将服务定义部分放在服务提供方 &lt;code>remote-provider.xml&lt;/code>，将服务引用部分放在服务消费方 &lt;code>remote-consumer.xml&lt;/code>。&lt;/li>
&lt;li>并在提供方增加暴露服务配置 &lt;code>&amp;lt;dubbo:service&amp;gt;&lt;/code>，在消费方增加引用服务配置 &lt;code>&amp;lt;dubbo:reference&amp;gt;&lt;/code>。&lt;/li>
&lt;/ul>
&lt;p>&lt;code>remote-provider.xml&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-xml" data-lang="xml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75">&amp;lt;!-- 和本地服务一样实现远程服务 --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;bean&lt;/span> id=&lt;span style="color:#2aa198">“xxxService”&lt;/span> class=&lt;span style="color:#2aa198">“com.xxx.XxxServiceImpl”&lt;/span> &lt;span style="color:#268bd2">/&amp;gt;&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75">&amp;lt;!-- 增加暴露远程服务配置 --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;dubbo:service&lt;/span> interface=&lt;span style="color:#2aa198">“com.xxx.XxxService”&lt;/span> ref=&lt;span style="color:#2aa198">“xxxService”&lt;/span> &lt;span style="color:#268bd2">/&amp;gt;&lt;/span> 
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>remote-consumer.xml&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-xml" data-lang="xml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75">&amp;lt;!-- 增加引用远程服务配置 --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;dubbo:reference&lt;/span> id=&lt;span style="color:#2aa198">“xxxService”&lt;/span> interface=&lt;span style="color:#2aa198">“com.xxx.XxxService”&lt;/span> &lt;span style="color:#268bd2">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75">&amp;lt;!-- 和本地服务一样使用远程服务 --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;bean&lt;/span> id=&lt;span style="color:#2aa198">“xxxAction”&lt;/span> class=&lt;span style="color:#2aa198">“com.xxx.XxxAction”&lt;/span>&lt;span style="color:#268bd2">&amp;gt;&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#268bd2">&amp;lt;property&lt;/span> name=&lt;span style="color:#2aa198">“xxxService”&lt;/span> ref=&lt;span style="color:#2aa198">“xxxService”&lt;/span> &lt;span style="color:#268bd2">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#268bd2">&amp;lt;/bean&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item></channel></rss>