Solon 1.2.12 released, new surprises

Solon is a micro development framework similar to Springboot. Emphasize: restraint + simplicity + openness principle. Strive: a smaller, faster, and more free experience.

The so-called smaller:

The kernel is 0.1m, and the smallest web development unit is 0.2m (compared to the Springboot project package, it is so small that it can be neglected)

The so-called faster:

The local helloworld test, Qps can reach as much as 120,000. Can refer to: " helloworld_wrk_test "

The so-called more freedom:

  • Free code manipulation:
// 除了注入模式之外,还可以按需手动
//
//手动获取配置
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()));
  • Freedom of frame choice:

You can use solon-web to quickly develop integration packages. You can also choose different plug-ins to assemble according to your project needs, for example: add solon.boot.jlhttp for non-Solon projects, 0.1m can enable the project to achieve http+mvc support; you can also use MVC to develop Socket applications.

You can also use the fast food solution: the solon-web package.

Major changes in this version:

1. Increase code affinity and reduce learning costs; remove all kinds of X prefixes

  • New Helloworld effect
@Controller
public class App{
    public static void main(String[] args){
        Solon.start(App.class, args);
    }
  
    @Mapping("/")
    public Object home(Context c){
        return "Hello world!";  
    }
}

2. Add BeanWrap semantic feature support

  • Through semantic characteristics, add meta-information description for Bean
//
// 这是一个数据主从库的示例
//
@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;
    }
}

3. Release a new component: SockeD, a Socket framework born for service development.

  • Support MVC+RPC development mode
//[服务端]
@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"));
  • Support single link two-way RPC development mode (based on the above example extension)
//[服务端]
@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;
    }
}
  • Support message sending + monitoring development mode
//[服务端]
@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);
  • Support news subscription development model
//[客户端]
@ClientEndpoint(uri = "tcp://localhost:28080")
public class ClientListener implements Listener {
    @Override
    public void onMessage(Session session, Message message) {
        //之后,就等着收消息
        System.out.println("客户端2:我收到了:" + message);
    }
}

Guess you like

Origin www.oschina.net/news/124573/solon-1-2-12-released