dubbo是一个分布式服务框架,是阿里巴巴开发的一个解决RPC远程调用优化的核心框架,包含负载均衡算法,能提高分布式系统的性能。
zookeeper是hadoop的一个子项目,主要用来解决分布式系统的数据一致性、状态同步、服务集群管理、配置同步等一系列的问题。本文使用zookeeper作为dubbo的服务注册中心。
当网站变大后,不可避免的需要拆分应用进行服务化,以提高开发效率,调优性能,节省关键竞争资源等。
当服务越来越多时,服务的URL地址信息就会爆炸式增长,配置管理变得非常困难,F5硬件负载均衡器的单点压力也越来越大。
当进一步发展,服务间依赖关系变得错踪复杂,甚至分不清哪个应用要在哪个应用之前启动,架构师都不能完整的描述应用的架构关系。
接着,服务的调用量越来越大,服务的容量问题就暴露出来,这个服务需要多少机器支撑?什么时候该加机器?等等……
在遇到这些问题时,都可以用Dubbo来解决。
随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进。
节点角色说明:
上图中,蓝色的表示与业务有交互,绿色的表示只对Dubbo内部交互。上述图所描述的调用流程如下:
将上面抽象的调用流程图展开,详细如图所示:
(1) 连通性:
(2) 健状性:
(3) 伸缩性:
(4) 升级性:
当服务集群规模进一步扩大,带动IT治理结构进一步升级,需要实现动态部署,进行流动计算,现有分布式服务架构不会带来阻力:
如图:某电商SOA服务。
那么Controller如何调用这些服务,首先需要将这些服务通过zookeeper注册到注册中心,然后Controller再从注册中心获取服务。
dubbo服务提供配置如下:
xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="mall-soa" logger="slf4j" />
<dubbo:registry address="${dubbo.registry.address}" timeout="5000" file="${dubbo.registry.cache}" />
<dubbo:provider delay="5000" timeout="30000" retries="0" token="zxngqplan" filter="tpsFilter,default,providerFilter">
<dubbo:parameter key="tps" value="100" />
<dubbo:parameter key="tps.interval" value="1000" />
dubbo:provider>
<dubbo:protocol name="dubbo" port="20880" />
id="cartService" class="com.zxng.mall.soa.order.impl.CartServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.order.api.CartService" ref="cartService" version="1.0.0" />
id="orderService" class="com.zxng.mall.soa.order.impl.OrderServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.order.api.OrderService" ref="orderService" version="1.0.0" />
id="settlementService" class="com.zxng.mall.soa.order.impl.SettlementServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.order.api.SettlementService" ref="settlementService" version="1.0.0" />
id="salesReturnService" class="com.zxng.mall.soa.order.impl.SalesReturnServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.order.api.SalesReturnService" ref="salesReturnService" version="1.0.0" />
id="groupService" class="com.zxng.mall.soa.promotion.impl.GroupServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.promotion.api.GroupService" ref="groupService" version="1.0.0" />
id="couponService" class="com.zxng.mall.soa.promotion.impl.CouponServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.promotion.api.CouponService" ref="couponService" version="1.0.0" />
id="balancePayService" class="com.zxng.mall.soa.pay.impl.BalancePayServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.BalancePayService" ref="balancePayService" version="1.0.0" />
id="couponPayService" class="com.zxng.mall.soa.pay.impl.CouponPayServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.CouponPayService" ref="couponPayService" version="1.0.0" />
id="wxPubPayService" class="com.zxng.mall.soa.pay.impl.WXPubPayServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.WXPubPayService" ref="wxPubPayService" version="1.0.0" />
id="wxAppPayService" class="com.zxng.mall.soa.pay.impl.WXAppPayServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.WXAppPayService" ref="wxAppPayService" version="1.0.0" />
id="alipayWapPayService" class="com.zxng.mall.soa.pay.impl.AlipayWapPayServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.AlipayWapPayService" ref="alipayWapPayService" version="1.0.0" />
id="alipayAppPayService" class="com.zxng.mall.soa.pay.impl.AlipayAppPayServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.AlipayAppPayService" ref="alipayAppPayService" version="1.0.0" />
id="paymentService" class="com.zxng.mall.soa.pay.impl.PaymentServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.PaymentService" ref="paymentService" version="1.0.0" />
id="webhookLogService" class="com.zxng.mall.soa.pay.impl.WebhookLogServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.pay.api.WebhookLogService" ref="webhookLogService" version="1.0.0" />
id="commodityService" class="com.zxng.mall.soa.sku.impl.CommodityServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.sku.api.CommodityService" ref="commodityService" version="1.0.0" />
id="commentService" class="com.zxng.mall.soa.sku.impl.CommentServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.sku.api.CommentService" ref="commentService" version="1.0.0" />
id="categoryService" class="com.zxng.mall.soa.sku.impl.CategoryServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.sku.api.CategoryService" ref="categoryService" version="1.0.0" />
id="merchantService" class="com.zxng.mall.soa.sku.impl.MerchantServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.sku.api.MerchantService" ref="merchantService" version="1.0.0" />
id="traceService" class="com.zxng.mall.soa.member.impl.TraceServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.member.api.TraceService" ref="traceService" version="1.0.0" />
id="collectionService" class="com.zxng.mall.soa.member.impl.CollectionServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.member.api.CollectionService" ref="collectionService" version="1.0.0" />
id="loginService" class="com.zxng.mall.soa.member.impl.LoginServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.member.api.LoginService" ref="loginService" version="1.0.0" />
id="memberService" class="com.zxng.mall.soa.member.impl.MemberServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.member.api.MemberService" ref="memberService" version="1.0.0" />
id="passportService" class="com.zxng.mall.soa.member.impl.PassportServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.member.api.PassportService" ref="passportService" version="1.0.0" />
id="expressService" class="com.zxng.mall.soa.thirdparty.impl.ExpressServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.thirdparty.api.ExpressService" ref="expressService" version="1.0.0" />
id="weixinPayApiService" class="com.zxng.mall.soa.thirdparty.impl.WeixinPayApiServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.thirdparty.api.WeixinPayApiService" ref="weixinPayApiService" version="1.0.0" />
id="alipayPayApiService" class="com.zxng.mall.soa.thirdparty.impl.AlipayPayApiServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.thirdparty.api.AlipayPayApiService" ref="alipayPayApiService" version="1.0.0" />
id="smsService" class="com.zxng.mall.soa.thirdparty.impl.SmsServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.thirdparty.api.SmsService" ref="smsService" version="1.0.0" />
id="weixinService" class="com.zxng.mall.soa.thirdparty.impl.WeixinServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.thirdparty.api.WeixinService" ref="weixinService" version="1.0.0" />
id="metaService" class="com.zxng.mall.soa.meta.impl.MetaServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.meta.api.MetaService" ref="metaService" version="1.0.0" />
id="commonService" class="com.zxng.mall.soa.meta.impl.CommonServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.meta.api.CommonService" ref="commonService" version="1.0.0" />
id="advertiseService" class="com.zxng.mall.soa.meta.impl.AdvertiseServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.meta.api.AdvertiseService" ref="advertiseService" version="1.0.0" />
id="columnService" class="com.zxng.mall.soa.meta.impl.ColumnServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.meta.api.ColumnService" ref="columnService" version="1.0.0" />
id="keywordService" class="com.zxng.mall.soa.meta.impl.KeywordServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.meta.api.KeywordService" ref="keywordService" version="1.0.0" />
id="siteConfigService" class="com.zxng.mall.soa.meta.impl.SiteConfigServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.meta.api.SiteConfigService" ref="siteConfigService" version="1.0.0" />
id="searchService" class="com.zxng.mall.soa.search.impl.SearchServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.search.api.SearchService" ref="searchService" version="1.0.0" />
id="weiXinUserService" class="com.zxng.mall.soa.weixin.impl.WeiXinUserServiceImpl" />
<dubbo:service interface="com.zxng.mall.soa.weixin.api.WeiXinUserService" ref="weiXinUserService" version="1.0.0" />
从注册中心获取服务配置如下:
xml version="1.0" encoding="UTF-8"?>
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="mall-web" logger="slf4j"/>
<dubbo:registry address="${dubbo.registry.address}" timeout="10000" file="${dubbo.registry.cache}" />
<dubbo:consumer check="false" filter="consumerFilter" />
<dubbo:reference id="cartService" interface="com.zxng.mall.soa.order.api.CartService" version="1.0.0" />
<dubbo:reference id="orderService" interface="com.zxng.mall.soa.order.api.OrderService" version="1.0.0" />
<dubbo:reference id="salesReturnService" interface="com.zxng.mall.soa.order.api.SalesReturnService" version="1.0.0" />
<dubbo:reference id="groupService" interface="com.zxng.mall.soa.promotion.api.GroupService" version="1.0.0" />
<dubbo:reference id="couponService" interface="com.zxng.mall.soa.promotion.api.CouponService" version="1.0.0" />
<dubbo:reference id="commodityService" interface="com.zxng.mall.soa.sku.api.CommodityService" version="1.0.0" />
<dubbo:reference id="commentService" interface="com.zxng.mall.soa.sku.api.CommentService" version="1.0.0" />
<dubbo:reference id="categoryService" interface="com.zxng.mall.soa.sku.api.CategoryService" version="1.0.0" />
<dubbo:reference id="merchantService" interface="com.zxng.mall.soa.sku.api.MerchantService" version="1.0.0" />
<dubbo:reference id="memberService" interface="com.zxng.mall.soa.member.api.MemberService" version="1.0.0" />
<dubbo:reference id="traceService" interface="com.zxng.mall.soa.member.api.TraceService" version="1.0.0" />
<dubbo:reference id="collectionService" interface="com.zxng.mall.soa.member.api.CollectionService" version="1.0.0" />
<dubbo:reference id="loginService" interface="com.zxng.mall.soa.member.api.LoginService" version="1.0.0" />
<dubbo:reference id="passportService" interface="com.zxng.mall.soa.member.api.PassportService" version="1.0.0" />
<dubbo:reference id="commonService" interface="com.zxng.mall.soa.meta.api.CommonService" version="1.0.0" />
<dubbo:reference id="metaService" interface="com.zxng.mall.soa.meta.api.MetaService" version="1.0.0" />
<dubbo:reference id="advertiseService" interface="com.zxng.mall.soa.meta.api.AdvertiseService" version="1.0.0" />
<dubbo:reference id="columnService" interface="com.zxng.mall.soa.meta.api.ColumnService" version="1.0.0" />
<dubbo:reference id="keywordService" interface="com.zxng.mall.soa.meta.api.KeywordService" version="1.0.0" />
<dubbo:reference id="siteConfigService" interface="com.zxng.mall.soa.meta.api.SiteConfigService" version="1.0.0" />
<dubbo:reference id="expressService" interface="com.zxng.mall.soa.thirdparty.api.ExpressService" version="1.0.0" />
<dubbo:reference id="weixinService" interface="com.zxng.mall.soa.thirdparty.api.WeixinService" version="1.0.0" />
<dubbo:reference id="searchService" interface="com.zxng.mall.soa.search.api.SearchService" version="1.0.0" />
<dubbo:reference id="alipayAppPayService" interface="com.zxng.mall.soa.pay.api.AlipayAppPayService" version="1.0.0" />
<dubbo:reference id="alipayWapPayService" interface="com.zxng.mall.soa.pay.api.AlipayWapPayService" version="1.0.0" />
<dubbo:reference id="wxPubPayService" interface="com.zxng.mall.soa.pay.api.WXPubPayService" version="1.0.0" />
<dubbo:reference id="wxAppPayService" interface="com.zxng.mall.soa.pay.api.WXAppPayService" version="1.0.0" />
<dubbo:reference id="weiXinUserService" interface="com.zxng.mall.soa.weixin.api.WeiXinUserService" version="1.0.0" />