阿里蚂蚁金服技术栈
一、SOFARPC
服务发布、引用以及调用的简单流程图如下:
- 当一个 SOFARPC 的应用启动时,如果发现当前应用需要发布 RPC 服务,那么 SOFARPC 会将该服务注册到配置中心,就是图中蓝色实线所示的过程。
- 当引用这个服务的 SOFA 应用启动时,会从配置中心订阅对应服务的地址,当配置中心收到订阅请求后,会将发布方的地址列表推送给订阅方,就是图中绿色实线所示的过程。
- 当引用服务的一方拿到地址以后,就可以调用服务了,就是图中蓝色虚线所示的过程。
使用步骤
依赖
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>rpc-enterprise-sofa-boot-starter</artifactId>
</dependency>
服务发布
1、设计服务接口类
/**
* 服务接口类
*/
public interface SampleService {
public String hello();
}
2、编写服务实现类
/**
* 实现服务接口:SampleService
*/
public class SampleServiceImpl implements SampleService{
@Override
public String hello() {
return "hello world";
}
}
3、在 Spring XML 中配置服务发布
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sofa="http://schema.alipay.com/sofa/schema/slite"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://schema.alipay.com/sofa/schema/slite http://schema.alipay.com/sofa/slite.xsd">
<!-- 声明服务的实现对象,以下类全名和接口全名,请根据自己的包名进行指定 -->
<bean id="sampleService" class=