turbo-rpc異步響應(yīng)式 RPC 框架
turbo-rpc 是一款速度超凡的異步響應(yīng)式RPC框架。
功能特點
僅支持異步調(diào)用,Service接口所有public方法返回值都必須為CompletableFuture。
配置定義在Service接口上,而非實現(xiàn)類上,方法實現(xiàn)者和調(diào)用者都不需要引入奇奇怪怪的注解。
支持REST調(diào)用。
支持失敗回退, 支持熔斷, 支持心跳, 支持自動重連。
支持自定義 服務(wù)注冊 負載均衡 序列化。
支持Filter, 可通過該機制實現(xiàn) Tracing 限流限速 黑白名單 等功能。
支持spring boot。
Quick Start
1.定義接口
@TurboService(version = "1.0.0")
public interface HelloService {
@TurboService(version = "1.0.0", rest = "hello")
default CompletableFuture<String> hello(String msg) {
// default實現(xiàn)會自動注冊為失敗回退方法,當(dāng)遠程調(diào)用失敗時執(zhí)行
return CompletableFuture.completedFuture("error");
}
}
2.服務(wù)端實現(xiàn)接口
@Component
public class HelloServiceImpl implements HelloService {
@Override
public CompletableFuture<String> hello(String msg) {
return CompletableFuture.completedFuture(msg);
}
}
3.配置turbo-server.conf, 聲明 服務(wù)器地址 序列化協(xié)議 注冊地址 等信息
4.服務(wù)端啟動
@SpringBootApplication(scanBasePackages = { "com.hello" })
@EnableTurboServer
public class TruboServerBootTest {
public static void main(String[] args) {
SpringApplication.run(TruboServerBootTest.class, args);
}
}
5.客戶端調(diào)用
@Component
public class HelloReferTest {
@Autowired
HelloService helloService;
public void doSomeThing(String msg) {
helloService.hello(msg)
.thenAccept(message -> System.out.println(message));
}
}
6.配置turbo-client.conf, 聲明 服務(wù)器地址 序列化協(xié)議 注冊地址 等信息
7.客戶端啟動
@SpringBootApplication(scanBasePackages = { "com.hello" })
@EnableTurboClient
public class HelloBootTest {
public static void main(String[] args) {
SpringApplication.run(HelloBootTest.class, args);
}
}評論
圖片
表情
