fastcall
是一款java
开发的高性能、轻量级、低配置、无侵入的RPC
框架。底层通信采用了netty
的nio
模式,应用层协议采用了自研的fastcall
协议,支持长连接。
在使用上,该框架采用了类似dubbo
的注解风格,对业务入侵小,并且对Spring
和非Spring
应用都有很好的支持。特别的,对于Spring boot
应用,提供fastcall-spring-boot-autoconfigure
和fastcall-spring-boot-starter
模块以支持应用的自动化配置。
框架本身支持可配置化的多服务注册中心,多负载均衡策略,多序列化方式。但对于未支持的情况,框架有预留扩展接口,使用者完全可以根据自己的喜好,实现扩展接口,实现自己的服务注册中心、负载策略和序列化方式。
与grpc
等其他rpc
框架不同,fastcall
拥有基本的服务治理能力,支持服务发现,服务发现,服务降级,负载均衡策略等功能。相比于grpc
的一大堆配置和生成代码的引入,fastcall
继承了dubbo
的优点,做到了低业务入侵性。
在线地址:http://stackoverflow.net
本地地址:gitbook文档
- 服务注册
- 服务发现
- 服务调用
- 负载均衡策略
- 调用超时与重试
- 服务降级
- 资源限制
$ git clone https://github.com/wormhole/fastcall
$ sh build.sh
详细的使用文档,请参照文档目录
5.1. 服务提供者 【样例代码】
- 新建
Spring boot
项目,并添加maven
依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>net.stackoverflow.fastcall</groupId>
<artifactId>fastcall-spring-boot-starter</artifactId>
<version>${fastcall.version}</version>
</dependency>
</dependencies>
application.properties
定义配置
#序列化方式
fastcall.serialize=json
#rpc处理并发线程数
fastcall.threads=10000
#应用层协议,及服务地址与端口
fastcall.transport.proto=fastcall
fastcall.transport.host=0.0.0.0
fastcall.transport.port=9966
#注册中心类型,及地址与端口
fastcall.registry.type=zookeeper
fastcall.registry.zookeeper.host=127.0.0.1
fastcall.registry.zookeeper.port=2181
fastcall.registry.zookeeper.session-timeout=5000
#日志
logging.level.root=INFO
logging.level.net.stackoverflow.fastcall=DEBUG
3、定义接口
public interface SayService {
String say(String content);
}
- 在服务实现类上,添加
@FastcallService
注解,标识这是需要暴露的服务。
@FastcallService(group = "group-1", version="1.0")
public class SayServiceImpl implements SayService {
private static final Logger log = LoggerFactory.getLogger(SayServiceImpl.class);
@Override
public String say(String content) {
return "hello " + content;
}
}
- 在启动类上添加注解
@EnableFastcall
(必加)指定需要扫描注解的包的位置,如果没有指定basePackages
或者basePackageClasses
,则从启动类的包路径包括子包,作为扫描路径
@SpringBootApplication
@EnableFastcall(basePackages = {"net.stackoverflow.fastcall.demo.provider"})
public class FastcallDemoProviderApplication {
public static void main(String[] args) {
SpringApplication.run(FastcallDemoProviderApplication.class, args);
}
}
5.2. 服务消费者 【样例代码】
- 新建
Spring boot
项目,并添加maven
依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>net.stackoverflow.fastcall</groupId>
<artifactId>fastcall-spring-boot-starter</artifactId>
<version>${fastcall.version}</version>
</dependency>
</dependencies>
application.properties
定义配置
#序列化方式
fastcall.serialize=json
#负载均衡策略
fastcall.balance=poll
#重试次数
fastcall.retry=0
#应用层协议
fastcall.transport.proto=fastcall
#注册中心类型,及地址与端口
fastcall.registry.type=zookeeper
fastcall.registry.zookeeper.host=127.0.0.1
fastcall.registry.zookeeper.port=2181
fastcall.registry.zookeeper.session-timeout=5000
#日志
logging.level.root=INFO
logging.level.net.stackoverflow.fastcall=DEBUG
- 在接口引用上,添加注解
@FastcallReference
,并指明分组,版本号,调用超时时间
@RestController
public class FastcallController {
@FastcallReference(group = "group-1", version="1.0", timeout=5000)
private SayService sayService;
@GetMapping("/say")
public String say(@RequestParam("content") String content) {
return sayService.say(content);
}
}
模块名 | 说明 |
---|---|
fastcall-parent | 对依赖版本进行统一管理 |
fastcall-core | 核心模块,包括序列化管理,注册中心管理,连接管理,应用层协议等 |
fastcall-spring-boot-autoconfigure | spring boot自动化配置模块,用于spring boot项目 |
fastcall-spring-boot-starter | spring boot starter模块,对自动化配置模块及相关依赖进行统一管理 |
fastcall-doc | gitbook文档 |
fastcall-demo-api | 样例工程,公共接口 |
fastcall-demo-provider | 样例工程,服务提供者 |
fastcall-demo-consumer | 样例工程,服务消费者 |
序列化类型 | json | protobuf | msgpack |
---|---|---|---|
是否支持 | ✔ | ❌ | ❌ |
注册中心 | zookeeper | redis | eureka |
---|---|---|---|
是否支持 | ✔ | ✔ | ❌ |
负载均衡 | random | poll | weight |
---|---|---|---|
是否支持 | ✔ | ✔ | ❌ |
协议 | fastcall | rmi | http |
---|---|---|---|
是否支持 | ✔ | ❌ | ❌ |
Fastcall software is licenced under the MIT License