内容简介:Solon 是一个微型的Java开发框架。项目从2018年启动以来,参考过大量前人作品;历时两年,4000多次的commit;内核保持0.1m的身材,超高的跑分,良好的使用体验。支持:RPC、REST API、MVC、WebSocket、Socket 等多...
Solon 是一个微型的 Java 开发框架。项目从2018年启动以来,参考过大量前人作品;历时两年,4000多次的commit;内核保持0.1m的身材,超高的跑分,良好的使用体验。支持:RPC、REST API、MVC、WebSocket、Socket 等多种开发模式。
Solon 强调:克制 + 简洁 + 开放的原则;力求:更小、更快、更自由的体验。
替代?那有什么异同之处?
《Solon 特性简集,相较于 Springboot 有什么区别?》
所谓更小:
内核0.1m,最小开发单位0.2m(相比Dubbo、Springboot项目包,小到可以乎略不计)
所谓更快:
本机helloworld测试,Qps可达12万之多。可参考:《helloworld_wrk_test》
所谓更自由:(代码操控自由)
// 除了注解模式之外,还可以按需手动
//
//手动获取配置(Props 为 Properties 增强版)
Props db = Solon.cfg().getProp("db");
//手动获取容器里的Bean
UserService userService = Aop.get(UserService.class);
//手动监听http post请求
Solon.global().post("/user/update", x-> userService.updateById(x.paramMap()));
//手动添加个RPC服务
Solon.global().add("/rpc/", HelloService.class, true);
//手动获取一个RPC服务消费端
HelloService helloService = Nami.builder().create(HelloService.class);
本次版本主要变化:
1、增加 Solon Cloud Breaker 接口规范(限流)
- 使用断路器进行限流
//1.通过注解,添加断路器实现限流
@Controller
public class BreakerDemo {
//添加断路器,以实现限流。demo 为断路器 name
@CloudBreaker("demo")
@Mapping("/demox/test")
public String test() throws Exception{
return "OK";
}
}
//2.通过过滤器添加断路器实现限流
Solon.global().filter((ctx, chain) -> {
if("/demox/test".equals(ctx.path())) {
try (AutoCloseable entry = CloudClient.breaker().entry("demo")) {
chain.doFilter(ctx);
}catch (BreakerException ex){
ctx.statusSet(403);
}
}
});
- 本地配置支持
solon.cloud.local:
breaker:
demo: 1 #qps
附:目前为止Solon Cloud 组件已规范并定义以下接口
接口定义 | 说明 |
---|---|
CloudBreakerService | 分布式断路器服务接口(实现组件有:guava-solon-plugin、sentinel-solon-plugin) |
CloudConfigService | 分布式配置服务接口 |
CloudDiscoveryService | 分布式注册也发现服务接口 |
CloudEventService | 分布式事件服务接口 |
CloudLockService | 分布式锁接口 |
CloudLogService | 分布式日志服务接口 |
CloudTraceService | 分布式链路跟踪服务接口 |
2、增加Solon Sloud Discovery本地配置支持,便于本地调试
solon.cloud.nacos:
discovery:
enable: false #禁用云端发现服务(本地的发现服务才会生效)
solon.cloud.local:
discovery:
service:
demo1:
- "http://localhost:8080"
demo2:
- "http://localhost:8081"
demo3:
- "tcp://localhost:28080"
//RPC 客户端注入,自动发现demo1的服务节点
@NamiClient(name="demo1")
Demo1Service service;
3、加强静态文件组件可配性和调试便利
- 增加缓存控制的max-age配置,例:
solon.staticfiles:
maxAge: 6000 #10分钟检测一次
- 调试模式下自动取消304缓存
方便调试时,即时刷新静态资源
4、Solon Data组件之缓存管理增加key模式(之前仅有tags模式)
- tags 模式:用于批量管控。(例如:多次分页查询的结果,可通过 tags 批量删除)
- key 模式:用于精准管控,使用时要注意 key 冲突。
//
// 混合使用示例:
//
@Controller
public class DemoController {
/**
* 执行结果缓存10秒,设定 key=test3_${label} ,并添加 tag=test3 标签(可以批量删除)
*/
@Cache(key = "test3_${label}", tags = "test3", seconds = 10)
@Mapping("/cache3/")
public String cache(int label) {
return LocalDateTime.now().toString();
}
/**
* 执行后,清除 tag=test3 的所有缓存,并更新 key=test3_${label} 的缓存数据
*/
@CachePut(key = "test3_${label}")
@CacheRemove(tags = "test3")
@Mapping("/cache3/update")
public String remove(int label) {
return "清除成功-" + new Date();
}
}
5、安全停止,升级为二段式暂停
//启动时,通过lumda函数,开启安全停止即可
//
Solon.start(TestApp.class, args, x -> x.enableSafeStop(true));
6、验证组件,增加自定义状态码支持
public class DemoValidator implements Validator<Demo> {
@Override
public Result validate(Context ctx, Demo anno, String name, StringBuilder tmp) {
//
// 旧版本,最终输出只返回 400 状态
//
return Result.failure(401);
}
}
附:入门示例
- 项目地址:https://gitee.com/noear/solon
- 入门教程示例:https://gitee.com/noear/solon_demo
- RPC入门教程示例:https://gitee.com/noear/solon_rpc_demo
- 进阶教程示例:https://gitee.com/noear/solon_advance_demo
以上所述就是小编给大家介绍的《Spring Boot 轻量替代框架 Solon 1.3.15 发布》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- looter——超轻量级爬虫框架
- 工具 | 一个轻量级业务中台开发框架
- 轻量级API测试框架Pandaria
- bilibili 轻量级业务框架正式开源
- 轻量级 Web 框架 Gin 结构分析
- Golang轻量级-高并发socket框架
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Algorithms on Strings, Trees and Sequences
Dan Gusfield / Cambridge University Press / 1997-5-28 / USD 99.99
String algorithms are a traditional area of study in computer science. In recent years their importance has grown dramatically with the huge increase of electronically stored text and of molecular seq......一起来看看 《Algorithms on Strings, Trees and Sequences》 这本书的介绍吧!