歡迎您光臨本站 註冊首頁

微服框架 Reactor-Guice 0.11 發布,自動掃描 Controller Service

←手機掃碼閱讀     admin @ 2019-06-06 , reply:0

Reactor-Guice 是一個基於 Reactor 和 Guice 的網路框架, 0.11 功能更新如下


1. 自動掃描帶有註解 @Controller 的類,將帶類里有 @Path 的方法,並加入到路由

2. 自動掃描帶有註解 @Service 的類,將類添加到 Guice 的 Module 中 bind,在其他類里通 @Inject 來注入

通過 Maven 引入


<dependency>
    <groupId>com.doopp</groupId>
    <artifactId>reactor-guice</artifactId>
    <version>0.11</version>
</dependency>

啟動服務 ( 例子 )


public static void main(String[] args) throws IOException {

    Properties properties = new Properties();
    properties.load(new FileInputStream(args[0]));

    ReactorGuiceServer.create()
        .bind(host, port)
        .createInjector(
            binder -> Names.bindProperties(binder, properties),
            new Module()
        )
        .setHttpMessageConverter(new MyGsonHttpMessageConverter())
        // .setHttpMessageConverter(new MyJacksonHttpMessageConverter())
        .setTemplateDelegate(new FreemarkTemplateDelegate())
        // .setTemplateDelegate(new ThymeleafTemplateDelegate())
        .basePackages("com.doopp.reactor.guice.app")
        .addFilter("/", TestFilter.class)
        .printError(true)
        .crossOrigin(true)
        .launch();
}

API 網關模式


ReactorGuiceServer.create()
        .bind(host, port)
        .setApiGatewayDispatcher(new MyApiGatewayDispatcher())
        .addFilter("/", TestFilter.class)
        .launch();

Reactor-Guice 聚焦於以下功能


0.0.3 支持註解 @GET @POST @PUT @DELETE @Products @PATH
0.0.3 靜態文件支持
0.0.3 支持 Websocket
0.0.4 自定義 uri filter
0.0.5 目錄下默認輸出 index.html
0.0.5 支持自定義 json lib,自帶 Gson 和 Jackson
0.0.5 可以上傳文件
0.0.6 POST 支持數組
0.0.7 支持自定義模板,自帶 Freemark 和 Thymeleaf
0.0.7 通過 Mono.just("redirect:/example") 支持跳轉
0.0.7 修復BUG,已經命名規範
0.0.8 API 網關模式,通過自定義的 Dispatcher 轉發請求,可 Filter 過濾
      修復頭信息重複的 BUG
      添加跨域頭支持,和 OPTIONS 請求的返回
0.0.9 支持 byte[] 類型輸出,便於輸出 protobuf
      修復跳轉的 BUG
      默認直接輸出返回的 JSON,而不對結果做包裝后再輸出
0.10  @BeanParam 註解支持將 Form Data , Json 或 Protobuf Data 轉換成本地對象
      上傳文件支持 byte[] ,UploadFile 或 File 類型,File 類型可以指定上傳文件保存的目錄

0.11  自動掃描 @Controller 並將方法加入到路由,規範符合 Reactor-Netty
      自動掃描 @Service 並將其添加到 Guice 的依賴注入中,規範符合 Guice

未來擴展支持
  udp server
  考慮引入 Jersey

[admin ]

來源:OsChina
連結:https://www.oschina.net/news/107261/reactor-guice-0-11-released
微服框架 Reactor-Guice 0.11 發布,自動掃描 Controller Service已經有253次圍觀

http://coctec.com/news/soft/show-post-206722.html