浅谈支付宝所用框架sofa
sofa是支付宝的核心框架,目前开发环境框架已经升级到sofa3,sofa的核心是spring,测试这边的接口测试用着是ats核心是testng,ats为sofa服务者,下面大致讲下sofa框架的结构和特色!
sofa分:biz层即业务层,core层俗称核心层,web层即展现层,common层也称数据层,test测试层。业务层的biz-service发布服务,打成jar包的方式供其他facade调用,引用服务在调数据层,如附件图
每个模块有自己独立的spring上下文。 各模块spring上下文隔离。 模块之间的服务调用,通过向sofa容器注册/引用服务完成。
可以在sofa中发布一个内部服务 可以在跨bundle引用其他bundle的内部服务 可以发布一个外部服务(ws、tr) 可以引用外部系统发布的服务(ws、tr) 理解软负载和统一服务模型 将springbean发不成jvm类型的sofa服务
<!-- spring bean声明 -->
<bean id="userService" class="com.alipay.yanyu.core.service.user.impl.UserServiceImpl" init-method="init"/>
<!-- 发布jvm服务:以接口作为服务的唯一标示符 -->
<sofa:service ref="userService" interface="com.alipay.yanyu.core.service.user.UserService" />
其他地方引用服务
<!-- 服务引入声明:以接口来查询服务 -->
<sofa:reference id="userService" interface="com.alipay.yanyu.core.service.user.UserService" />
<!-- 带uniqueId的服务发布 -->
<sofa:service ref="userService" interface="com.alipay.yanyu.core.service.user.UserService" uniqueId="uniqueId1" />
<!-- 带uniqueId的服务引用 -->
<sofa:reference id="userService" interface="com.alipay.yanyu.core.service.user.UserService" uniqueId="uniqueId1" />
rpc服务发布 <bean id="userFacade" class="com.alipay.yanyu.biz.service.impl.UserFacadeImpl" />
<!-- 发布rpc服务 -->
<sofa:service ref="userFacade" interface="com.alipay.yanyu.common.service.facade.UserFacade" >
<!-- 增加ws绑定 -->
<sofa:binding.ws />
</sofa:service>
rpc服务引用 <sofa:reference id="userFacade" interface="com.alipay.yanyu.common.service.facade.UserFacade"> <sofa:binding.ws /> </sofa:reference>
服务发布: 默认绑定:sofa:binding/ 跨JVM绑定:sofa:binding.ws/、sofa:binding.tr/ 服务引用: 职能声明一种绑定
不同bundle之间的引用和依赖通过pom.xml文件加入依赖 jar包引用 <dependency> <groupId>com.alipay.sofa.runtime</groupId> <artifactId>sofa-runtime-esb</artifactId> </dependency>
log4j中配置日志相关内容
sofa的配置文件: dbconf数据库配置文件(有几套环境可以选择) sofaTestConfig文件配置接口以及系统间的调用(本地) antx文件配置系统间的调用(服务器上) pom.xml文件各种依赖的添加