Reactor-Guice基于 Reactor 的 Guice 框架
Reactor-Guice 是一个基于 Reactor 的 Guice 框架,集成了 Google Guice 和 Reactor-netty 框架。
通过 Maven 引入后,简单的代码就可以启动你的 http 和 websocket 服务
并搭建你的微服务
https://github.com/koocyton/reactor-guice-example 是一个实例
Reactor-Guice 聚焦于以下功能
1. 通过 JAX-RS 注解注入来完成 Route 配置
2. 通过 @Products 来指定返回的类型
3. 通过继承 AbstractWebSocketServerHandle 获得 Websocket 服务路径
4. 实现 KReactorFilter 对访问路径过滤
以下是含 数据库 和 Redis 功能的配置
Injector injector = Guice.createInjector(
// application Properties
binder -> Names.bindProperties(binder, properties),
// mybatis
new MyBatisModule() {
@Override
protected void initialize() {
install(JdbcHelper.MySQL);
bindDataSourceProviderType(HikariDataSourceProvider.class);
bindTransactionFactoryType(JdbcTransactionFactory.class);
addMapperClasses("com.doopp.gauss.app.dao.mapper");
addInterceptorClass(PageInterceptor.class);
}
},
// redis
new RedisModule(),
// application
new ApplicationModule()
);
KReactorServer.create()
.bind(host, port)
.injector(injector)
.handlePackages("com.doopp.gauss.app.handle.v1")
.addFilter("/", AppFilter.class)
.launch();评论
