一敲茄、簡(jiǎn)介
SOFARPC 是螞蟻金服開(kāi)源的一款基于 Java 實(shí)現(xiàn)的 RPC 服務(wù)框架充包,為應(yīng)用之間提供遠(yuǎn)程服務(wù)調(diào)用能力副签,具有高可伸縮性,高容錯(cuò)性基矮,目前螞蟻金服所有的業(yè)務(wù)的相互間的 RPC 調(diào)用都是采用 SOFARPC淆储。SOFARPC 為用戶提供了負(fù)載均衡,流量轉(zhuǎn)發(fā)家浇,鏈路追蹤本砰,鏈路數(shù)據(jù)透?jìng)鳎收咸蕹裙δ堋?br>
SOFARPC 還支持不同的協(xié)議钢悲,目前包括 bolt点额,RESTful舔株,dubbo,H2C 協(xié)議進(jìn)行通信
二还棱、使用
1.HelloSyncService接口
public interface HelloSyncService {
String saySync(String string);
}
2.HelloSyncServiceImpl實(shí)現(xiàn)類(lèi)
public class HelloSyncServiceImpl implements HelloSyncService {
@Override
public String saySync(String string) {
return string;
}
}
3.DemoApplication啟動(dòng)類(lèi)
@ImportResource({ "classpath*:applicationContext.xml" })
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(DemoApplication.class);
ApplicationContext applicationContext = springApplication.run(args);
HelloSyncService helloSyncServiceReference = (HelloSyncService) applicationContext
.getBean("helloSyncServiceReference");
System.out.println(helloSyncServiceReference.saySync("sync"));
}
}
4.applicationContext.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://sofastack.io/schema/sofaboot"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://sofastack.io/schema/sofaboot http://sofastack.io/schema/sofaboot.xsd"
default-autowire="byName">
<bean id="helloSyncServiceImpl" class="com.sofarpctest.demo.provider.HelloSyncServiceImpl"/>
<sofa:service ref="helloSyncServiceImpl" interface="com.sofarpctest.demo.provider.HelloSyncService">
<sofa:binding.bolt/>
</sofa:service>
<sofa:reference id="helloSyncServiceReference" interface="com.sofarpctest.demo.provider.HelloSyncService">
<sofa:binding.bolt/>
</sofa:reference>
</beans>