Sofa框架概述
SOFA是Service Oriented Fabric Architecture是一种分布式架构解决方案,是一个应用中间件,包含了RPC、消息、监控和服务治理。
开发框架的组成
一个标准的sofa工程从上到下可以分为测试层、展现层、业务层、核心领域层和通用层,并且从测试层到通用层是层级依赖的。一般来说,如果下层模块依赖了上层模块的代码,那么就会出现循环依赖,导致工程报错。在通用层,又可以分为数据访问层、服务引用和应用jar包。
sofa模块与jar包的区别
1、一个 SOFA 模块的 META-INF 目录下,有一个 MANIFEST.MF 文件,这份文件里面定义了 SOFA 模块的名称以及模块之间的依赖关系。
2、在一个 SOFA 模块的 META-INF/spring 目录下,可以放置任意多的 Spring 配置文件,这些配置文件,SOFA 会自定把它们作为本模块的 Spring 配置加载起来。
服务发布与引用
在使用sofa开发的时候,使用最多的就是sofa服务的引用与发布了,具体来说,服务发布与引用的流程如下:
1、XML
<bean id="sampleService" class="com.alipay.sofa.runtime.test.service.SampleServiceImpl">
<!-- 服务的发布 -->
<sofa:service interface="com.alipay.sofa.runtime.test.service.SampleService" ref="sampleService" />
<!-- 服务的引用 -->
<sofa:reference interface="com.alipay.sofa.runtime.test.service.SampleService" id="sampleServiceRef" />
2、Annotation
@SofaService
public class SampleImpl implements SampleInterface {
public void test() {
}
}
@SofaService(interfaceType=SampleInterface.class)
public class SampleImpl implements SampleInterface, Serializable {
public void test() {
}
}
public class SampleServiceRef {
@SofaReference
private SampleService sampleService;
}
public class SampleServiceRef {
@SofaReference(interfaceType=SampleService.class)
private SampleService sampleService;
}
3、编程API
<sofa:service interface="com.alipay.sofa.runtime.test.service.SampleService" ref="sampleService1" unique-id="ss1">
</sofa:service>
<sofa:service interface="com.alipay.sofa.runtime.test.service.SampleService" ref="sampleService2" unique-id="ss2">
</sofa:service>
<sofa:reference interface="com.alipay.sofa.runtime.test.service.SampleService" id="sampleService" unique-id="ss1">
</sofa:reference>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39