跳至内容
技术分享
站点工具
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
登录
搜索
您的足迹:
服务器技术:微服务:dubbo和spring_cloud微服务架构对比
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
<h2 class="rich_media_title" style="font-weight:400;font-size:24px;line-height:1.4;font-family:'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;">Dubbo和Spring Cloud微服务架构对比</h2><p>原文:https://blog.csdn.net/zhangweiwei2020/article/details/78646252</p><p><br/><br/><span style="color:rgb(89,89,89);font-family:'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;font-size:15px;letter-spacing:1px;background-color:rgb(239,239,239);">微服务架构是互联网很热门的话题,是互联网技术发展的必然结果。它提倡将单一应用程序划分成一组小的服务,服务之间互相协调、互相配合,为用户提供最终价值。</span><br/></p><p style="clear:both;min-height:1em;text-align:center;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">虽然微服务架构没有公认的技术标准和规范或者草案,但业界已经有一些很有影响力的开源微服务架构框架提供了微服务的关键思路,例如 Dubbo 和 Spring Cloud。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">各大互联网公司也有自研的微服务框架,但其模式都与这二者相差不大。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;">微服务主要的优势</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">降低复杂度</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">将原来耦合在一起的复杂业务拆分为单个服务,规避了原本复杂度无止境的积累。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">每一个微服务专注于单一功能,并通过定义良好的接口清晰表述服务边界;每个服务开发者只专注服务本身,通过使用缓存、DAL 等各种技术手段来提升系统的性能,而对于消费方来说完全透明。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">可独立部署</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">由于微服务具备独立的运行进程,所以每个微服务可以独立部署。当业务迭代时只需要发布相关服务的迭代即可,降低了测试的工作量同时也降低了服务发布的风险。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">容错</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">在微服务架构下,当某一组件发生故障时,故障会被隔离在单个服务中。比如通过限流、熔断等方式降低错误导致的危害,保障核心业务正常运行。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">扩展</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">单块架构应用也可以实现横向扩展,就是将整个应用完整的复制到不同的节点。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">当应用的不同组件在扩展需求上存在差异时,微服务架构便体现出其灵活性,因为每个服务可以根据实际需求独立进行扩展。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">本文主要围绕微服务的技术选型、通讯协议、服务依赖模式、开始模式、运行模式等几方面来综合比较 Dubbo 和 Spring Cloud 这 2 种开发框架。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">架构师可以根据公司的技术实力并结合项目的特点来选择某个合适的微服务架构平台,以此稳妥地实施项目的微服务化改造或开发进程。</span></p><h2 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h2><h2 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h2><p style="clear:both;min-height:1em;">核心部件</p><h2 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h2><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">微服务的核心要素在于服务的发现、注册、路由、熔断、降级、分布式配置,基于上述几种必要条件对 Dubbo 和 Spring Cloud 做出对比。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h3><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">总体架构</p><h3 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h3><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">Dubbo 核心部件(如下图):</span></p><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Provider:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">暴露服务的提供方,可以通过 jar 或者容器的方式启动服务。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Consumer:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">调用远程服务的服务消费方。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Registry:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务注册中心和发现中心。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Monitor:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">统计服务和调用次数,调用时间监控中心。(Dubbo 的控制台页面中可以显示,目前只有一个简单版本。)</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Container:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务运行的容器。</span></p></li></ul><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127161905651" alt=""/><br/><span style="font-size:14px;"><span style="color:rgb(89,89,89);letter-spacing:1px;">Dubbo 总体架构</span></span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">Spring Cloud总体架构(如下图):</span></p><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Service Provider: </span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">暴露服务的提供方。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Service Consumer:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">调用远程服务的服务消费方。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">EureKa Server: </span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务注册中心和服务发现中心。</span></p></li></ul><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127161916320" alt=""/></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><span style="font-size:14px;"><span style="color:rgb(89,89,89);letter-spacing:1px;">Spring Cloud 总体架构</span></span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">点评:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">从整体架构上来看,二者模式接近,都需要服务提供方,注册中心,服务消费方。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h3><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">微服务架构核心要素</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127161941661" alt=""/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 只是实现了服务治理,而 Spring Cloud 子项目分别覆盖了微服务架构下的众多部件,服务治理只是其中的一个方面。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 提供了各种 Filter,对于上述中“无”的要素,可以通过扩展 Filter 来完善。</span><span style="color:rgb(89,89,89);font-size:15px;letter-spacing:1px;line-height:2em;">例如:</span></p><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">分布式配置:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">可以使用淘宝的 diamond、百度的 disconf 来实现分布式配置管理。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务跟踪:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">可以使用京东开源的 Hydra,或者扩展 Filter 用 Zippin 来做服务跟踪。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">批量任务:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">可以使用当当开源的 Elastic-Job、tbschedule。</span></p></li></ul><p style="clear:both;min-height:1em;line-height:1.75em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">点评:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">从核心要素来看,Spring Cloud 更胜一筹,在开发过程中只要整合 Spring Cloud 的子项目就可以顺利的完成各种组件的融合,而 Dubbo 却需要通过实现各种 Filter 来做定制,开发成本以及技术难度略高。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h2 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h2><p style="clear:both;min-height:1em;">通讯协议</p><h2 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h2><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">基于通讯协议层面对 2 种框架支持的协议类型以及运行效率方面进行比较。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h3><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">支持协议</p><h3 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h3><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="color:rgb(89,89,89);letter-spacing:1px;">Dubbo</span></h3><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"><br/></span></h3><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">Dubbo 使用 RPC 通讯协议,提供序列化方式如下:</span></h3><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 缺省协议采用单一长连接和 NIO 异步通讯,适合于小数据量大并发的服务调用,以及服务消费者机器数远大于服务提供者机器数的情况。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">RMI:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">RMI 协议采用 JDK 标准的 java.rmi.* 实现,采用阻塞式短连接和 JDK 标准序列化方式。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Hessian:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Hessian 协议用于集成 Hessian 的服务,Hessian 底层采用 HTTP 通讯,采用 Servlet 暴露服务,Dubbo 缺省内嵌 Jetty 作为服务器实现。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">HTTP:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">采用 Spring 的 Http Invoker 实现。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Webservice:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">基于 CXF 的 frontend-simple 和 transports-http 实现。</span></p></li></ul><p style="clear:both;min-height:1em;line-height:1.75em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="color:rgb(89,89,89);letter-spacing:1px;">Spring Cloud</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Spring Cloud 使用 HTTP 协议的 REST API。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h3><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">性能比较</p><h3 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h3><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">使用一个 Pojo 对象包含 10 个属性,请求 10 万次,Dubbo 和 Spring Cloud 在不同的线程数量下,每次请求耗时(ms)如下:</span></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127162011611" alt=""/><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">说明:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">客户端和服务端配置均采用阿里云的 ECS 服务器,4 核 8G 配置,Dubbo 采用默认的 Dubbo 协议。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">点评:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 支持各种通信协议,而且消费方和服务方使用长链接方式交互,通信速度上略胜 Spring Cloud,如果对于系统的响应时间有严格要求,长链接更合适。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h2 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h2><p style="clear:both;min-height:1em;">服务依赖方式</p><h2 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h2><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">Dubbo</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">服务提供方与消费方通过接口的方式依赖,服务调用设计如下:</span></p><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Interface 层:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务接口层,定义了服务对外提供的所有接口。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Molel 层:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务的 DTO 对象层。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Business层:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">业务实现层,实现 Interface 接口并且和 DB 交互。</span></p></li></ul><p style="clear:both;min-height:1em;line-height:1.75em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">因此需要为每个微服务定义各自的 Interface 接口,并通过持续集成发布到私有仓库中。调用方应用对微服务提供的抽象接口存在强依赖关系,开发、测试、集成环境都需要严格的管理版本依赖。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">通过 maven 的 install & deploy 命令把 Interface 和 Model 层发布到仓库中,服务调用方只需要依赖 Interface 和 Model 层即可。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">在开发调试阶段只发布 Snapshot 版本,等到服务调试完成再发布 Release 版本,通过版本号来区分每次迭代的版本。通过 xml 配置方式即可接入 Dubbo,对程序无入侵。</span></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127162024042" alt=""/></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><span style="font-size:14px;"><span style="color:rgb(89,89,89);letter-spacing:1px;">Dubbo 接口依赖方式</span></span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">Spring Cloud</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务提供方和服务消费方通过 Json 方式交互,因此只需要定义好相关 Json 字段即可,消费方和提供方无接口依赖。通过注解方式来实现服务配置,对于程序有一定入侵。</span></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127162031791" alt=""/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">点评:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 服务依赖略重,需要有完善的版本管理机制,但是程序入侵少。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="color:rgb(89,89,89);font-size:15px;letter-spacing:1px;line-height:2em;">而 Spring Cloud 通过 Json 交互,省略了版本管理的问题,但是具体字段含义需要统一管理,自身 Rest API 方式交互,为跨平台调用奠定了基础。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h2 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h2><p style="clear:both;min-height:1em;">组件运行流程</p><h2 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h2><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">Dubbo</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">下图中的每个组件都是需要部署在单独的服务器上,Gateway 用来接受前端请求、聚合服务,并批量调用后台原子服务。每个 Service 层和单独的 DB 交互。</span></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127162040322" alt=""/></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><span style="font-size:14px;"><span style="color:rgb(89,89,89);letter-spacing:1px;">Dubbo 组件运行流程</span></span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">Dubbo 组件运行:</span></p><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Gateway:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">前置网关,具体业务操作,Gateway 通过 Dubbo 提供的负载均衡机制自动完成。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Service:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">原子服务,只提供该业务相关的原子服务。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Zookeeper:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">原子服务注册到 ZK 上。</span></p></li></ul><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127162048355" alt=""/></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><span style="font-size:14px;"><span style="color:rgb(89,89,89);letter-spacing:1px;">Spring Cloud 组件运行</span></span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p><p><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span><span style="display:block;background-color:rgb(89,89,89);"></span></p><p style="clear:both;min-height:1em;">Spring Cloud</p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">Spring Cloud组件运行:</span></p><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">所有请求都统一通过 API 网关(Zuul)来访问内部服务。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">网关接收到请求后,从注册中心(Eureka)获取可用服务。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">由 Ribbon 进行均衡负载后,分发到后端的具体实例。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">微服务之间通过 Feign 进行通信处理业务。</span></p></li></ul><p style="clear:both;min-height:1em;line-height:1.75em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">点评:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">业务部署方式相同,都需要前置一个网关来隔绝外部直接调用原子服务的风险。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 需要自己开发一套 API 网关,而 Spring Cloud 则可以通过 Zuul 配置即可完成网关定制。使用方式上 Spring Cloud 略胜一筹。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><h2 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h2><p style="clear:both;min-height:1em;">微服务架构组成以及注意事项</p><h2 style="font-weight:400;font-size:16px;line-height:2em;"><br/></h2><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">到底使用是 Dubbo 还是 Spring Cloud 并不重要,重点在于如何合理的利用微服务。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">下面是一张互联网通用的架构图,其中每个环节都是微服务的核心部分。</span></p><p style="clear:both;min-height:1em;text-align:center;line-height:2em;"><img src="https://img-blog.csdn.net/20171127162056684" alt=""/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">架构分解:</span></p><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">网关集群:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">数据的聚合、实现对接入客户端的身份认证、防报文重放与防数据篡改、功能调用的业务鉴权、响应数据的脱敏、流量与并发控制等。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">业务集群:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">一般情况下移动端访问和浏览器访问的网关需要隔离,防止业务耦合。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Local Cache:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">由于客户端访问业务可能需要调用多个服务聚合,所以本地缓存有效的降低了服务调用的频次,同时也提示了访问速度。本地缓存一般使用自动过期方式,业务场景中允许有一定的数据延时。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务层:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">原子服务层,实现基础的增删改查功能,如果需要依赖其他服务需要在 Service 层主动调用。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Remote Cache:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">访问 DB 前置一层分布式缓存,减少 DB 交互次数,提升系统的TPS。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">DAL:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">数据访问层,如果单表数据量过大则需要通过 DAL 层做数据的分库分表处理。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">MQ:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">消息队列用来解耦服务之间的依赖,异步调用可以通过 MQ 的方式来执行。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">数据库主从:</span><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务化过程中必经的阶段,用来提升系统的 TPS。</span></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></p></li></ul><h3 style="font-weight:400;font-size:16px;line-height:1.75em;"><br/></h3><h3 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;letter-spacing:1px;color:rgb(71,193,168);">注意事项:</span></h3><ul class=" list-paddingleft-2"><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务启动方式建议使用jar方式启动,启动速度快,更容易监控。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">缓存、缓存、缓存,系统中能使用缓存的地方尽量使用缓存,通过合理的使用缓存可以有效的提高系统的TPS。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">服务拆分要合理,尽量避免因服务拆分而导致的服务循环依赖。</span></p></li><li><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">合理的设置线程池,避免设置过大或者过小导致系统异常。</span></p></li></ul><h2 style="font-weight:400;font-size:16px;line-height:1.75em;"><br/></h2><h2 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span></h2><p style="clear:both;min-height:1em;">总结</p><h2 style="font-weight:400;font-size:16px;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;"></span><br/></h2><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 出生于阿里系,是阿里巴巴服务化治理的核心框架,并被广泛应用于中国各互联网公司;只需要通过 Spring 配置的方式即可完成服务化,对于应用无入侵,</span><span style="color:rgb(89,89,89);font-size:15px;letter-spacing:1px;line-height:2em;">设计的目的还是服务于自身的业务为主。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="color:rgb(89,89,89);font-size:15px;letter-spacing:1px;line-height:2em;">虽然阿里内部原因 Dubbo 曾经一度暂停维护版本,但是框架本身的成熟度以及文档的完善程度,完全能满足各大互联网公司的业务需求。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="color:rgb(89,89,89);font-size:15px;letter-spacing:1px;line-height:2em;">如果我们使用配置中心、分布式跟踪这些内容都需要自己去集成,这样无形中增加了使用 Dubbo 的难度。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Spring Cloud 是大名鼎鼎的 Spring 家族的产品, 专注于企业级开源框架的研发。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Spring Cloud 自从发布到现在,仍然在不断的高速发展,几乎考虑了服务治理的方方面面,开发起来非常的便利和简单。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">Dubbo 于 2017 年开始又重启维护,发布了更新后的 2.5.7 版本,而 Spring Cloud 更新的非常快,目前已经更新到 Finchley.M2。</span></p><p style="clear:both;min-height:1em;line-height:2em;"><br/></p><p style="clear:both;min-height:1em;text-align:justify;line-height:2em;"><span style="font-size:15px;color:rgb(89,89,89);letter-spacing:1px;">因此,企业需要根据自身的研发水平和所处阶段选择合适的架构来解决业务问题,不管是 Dubbo 还是 Spring Cloud 都是实现微服务有效的工具。</span></p><p><span style="color:rgb(89,89,89);font-family:'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;font-size:15px;letter-spacing:1px;background-color:rgb(239,239,239);">微服务架构是互联网很热门的话题,是互联网技术发展的必然结果。它提倡将单一应用程序划分成一组小的服务,服务之间互相协调、互相配合,为用户提供最终价值</span></p><p><br/></p>
服务器技术/微服务/dubbo和spring_cloud微服务架构对比.1535514574.txt.gz
· 最后更改: 2018/09/10 18:01 (外部编辑)
页面工具
显示页面
修订记录
反向链接
页面重命名
回到顶部