Solon 一個相似Springboot的微型開發框架。強調:剋制 + 簡潔 + 開放的原則。力求:更小、更快、更自由的體驗。java
內核0.1m,最小Web開發單位0.2m(相比Springboot項目包,小到能夠乎略不計了)git
本機helloworld測試,Qps可達12萬之多。可參考:《helloworld_wrk_test》github
// 除了注入模式以外,還能夠按需手動 // //手動獲取配置 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()));
能夠用solon-web這樣的快速開發集成包。也能夠按項目須要選擇不一樣的插件組裝,好比:爲非Solon項目添加solon.boot.jlhttp,0.1m便可讓項目實現http+mvc支持;還能夠用MVC開發Socket應用。web
也能夠用快餐方案:solon-web 這個組合包。session
@Controller public class App{ public static void main(String[] args){ Solon.start(App.class, args); } @Mapping("/") public Object home(Context c){ return "Hello world!"; } }
// // 這是一個數據主從庫的示例 // @Configuration public class Config { //申明 db2 是 db1 爲的從庫 @Bean(value = "db1", attrs = { "slaves=db2" }) public DataSource db1(@Inject("${test.db1}") HikariDataSource dataSource) { return dataSource; } @Bean("db2") public DataSource db2(@Inject("${test.db2}") HikariDataSource dataSource) { return dataSource; } }
//[服務端] @Mapping(value = "/demoe/rpc", method = MethodType.SOCKET) @Component(remoting = true) public class HelloRpcServiceImpl implements HelloRpcService { public String hello(String name) { return "name=" + name; } } //[客戶端] var rpc = SocketD.create("tcp://localhost:28080", HelloRpcService.class); System.out.println("RPC result: " + rpc.hello("noear"));
//[服務端] @Mapping(value = "/demoe/rpc", method = MethodType.SOCKET) @Component(remoting = true) public class HelloRpcServiceImpl implements HelloRpcService { public String hello(String name) { // //[服務端] 調用 [客戶端] 的 rpc,從而造成單連接雙向RPC // NameRpcService rpc = SocketD.create(Context.current(), NameRpcService.class); name = rpc.name(name); return "name=" + name; } }
//[服務端] @ServerEndpoint public class ServerListener implements Listener { @Override public void onMessage(Session session, Message message) { if(message.flag() == MessageFlag.heartbeat){ System.out.println("服務端:我收到心跳"); }else { System.out.println("服務端:我收到:" + message); //session.send(Message.wrapResponse(message, "我收到了")); } } } //[客戶端] var session = SocketD.createSession("tcp://localhost:28080"); session.send("noear"); //session.sendAndCallback("noear", (rst)->{}); //發送並異常回調 //var rst = session.sendAndResponse("noear"); //發送並等待響應 System.out.println(rst);
//[客戶端] @ClientEndpoint(uri = "tcp://localhost:28080") public class ClientListener implements Listener { @Override public void onMessage(Session session, Message message) { //以後,就等着收消息 System.out.println("客戶端2:我收到了:" + message); } }