当前位置 博文首页 > Solon rpc 1.2.18 发布,突出Rpc特性
Solon 是一个微型的Java RPC开发框架。项目从2018年启动以来,参考过大量前人作品;历时两年,3500多次的commit;内核保持0.1m的身材,超高的跑分,良好的使用体验。支持:Rpc、Rest api、Mvc 多种开发模式。
Solon 强调:克制 + 简洁 + 开放的原则;力求:更小、更快、更自由的体验。
内核0.1m,最小开发单位0.2m(相比Dubbo、Springboot项目包,小到可以乎略不计)
本机helloworld测试,Qps可达12万之多。可参考:《helloworld_wrk_test》
// 除了注入模式之外,还可以按需手动
//
//手动获取配置
Map<String,String> db = Solon.cfg().getMap("db");
//手动获取容器里的Bean
UserService userService = Aop.get(UserService.class);
//手动监听http post请求
Solon.global().post("/user/update", x-> userService.updateById(x.paramMap()));
Solonn rpc 框架分为两部分:Nami 承载客户端的工作;Solon.boot 承载服务端的工作;Solon 做为容器贯穿前后
架构示意图
使用时须引入有通道和编码包;也可根据需求定制自己的通道与编码方案
Springboot 客户端集成示例 demo10.client_springboot
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>1.2.18</version>
</parent>
<dependencies>
<dependency>
<groupId>org.noear</groupId>
<artifactId>nami.coder.snack3</artifactId>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>nami.channel.http.okhttp</artifactId>
</dependency>
</dependencies>
public class ClientApp {
public static void main(String[] args) {
Solon.start(ClientApp.class, args);
//
// 默认使用json解码
//
HelloService helloService = Nami.builder()
.upstream(() -> "http://localhost:8080").create(HelloService.class);
String result = helloService.hello("noear");
System.out.println("Rpc result: " + result);
}
}
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>1.2.18</version>
</parent>
<dependencies>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.serialization.snack3</artifactId>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.boot.jlhttp</artifactId>
</dependency>
</dependencies>
public class ServerApp {
public static void main(String[] args) {
Solon.start(ServerApp.class, args);
}
}
@Mapping("/")
@Component(remoting = true)
public class HelloServiceImpl implements HelloService {
@Override
public String hello(String name) {
return "hello: " + name;
}
}
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>1.2.18</version>
</parent>
<dependencies>
<dependency>
<groupId>org.noear</groupId>
<artifactId>nami.coder.hessian</artifactId>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>nami.channel.socketd.smartsocket</artifactId>
</dependency>
</dependencies>
public class ClientApp {
public static void main(String[] args) {
Solon.start(ClientApp.class, args);
//
// 默认使用json解码
//
HelloService helloService = Nami.builder()
.upstream(() -> "http://localhost:8080").decoder(HessianDecoder.instance).create(HelloService.class);
String result = helloService.hello("noear");
System.out.println("Rpc result: " + result);
}
}
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>1.2.18</version>
</parent>
<dependencies>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.serialization.hession</artifactId>
</dependency>
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon.boot.socketd.smartsocket</artifactId>
</dependency>
</dependencies>
public class ServerApp {
public static void main(String[] args) {
Solon.start(ServerApp.class, args);
}
}
@Mapping(value = "/",method = MethodType.SOCKET)
@Component(remoting = true)
public class HelloServiceImpl implements HelloService {
@Override
public String hello(String name) {
return "hello: " + name;
}
}