Java云原生-Micronaut Quarkus SpringNative
Redhat提供的Java云原生開發(fā)的圖書
https://developers.redhat.com/e-books/modernizing-enterprise-java
https://developers.redhat.com/e-books/quarkus-spring-developers
Quarkus
https://quarkus.io/guides/
近幾年由于云原生技術(shù)的普及,越來越多的用戶開始使用容器來運(yùn)行微服務(wù)應(yīng)用。微服務(wù)架構(gòu)的引入,使我們的服務(wù)顆粒度變得越來越小,輕量且能快速啟動(dòng)的應(yīng)用能夠更好的適應(yīng)容器化環(huán)境。 以我們目前常規(guī)的Spring Boot應(yīng)用來說,一般Restful服務(wù)的jar包大概是30M左右,如果我們將JDK以及相關(guān)應(yīng)用打包成docker鏡像文件大概是140M左右。而常規(guī)的Go語言的可執(zhí)行程序生成鏡像包一般不會(huì)超過50M。如何讓臃腫的Java應(yīng)用瘦身使他易于容器化,成為Java應(yīng)用云原生化需要解決的問題。
紅帽開源的Quarkus項(xiàng)目,借助開源社區(qū)的力量,通過對(duì)業(yè)界廣泛使用的框架進(jìn)行了適配,并結(jié)合云原生應(yīng)用的特點(diǎn),提供了一套端到端的Java云原生應(yīng)用解決方案。雖然開源時(shí)間較短,但是生態(tài)方面也已經(jīng)達(dá)到可用的狀態(tài),自身包含擴(kuò)展框架,已經(jīng)支持像Netty、Undertow、Hibernate、JWT等框架,足以用于開發(fā)企業(yè)級(jí)應(yīng)用,用戶也可以基于擴(kuò)展框架自行擴(kuò)展。
Quarkus定位為GraalVM*和OpenJDK HotSpot量身定制的一個(gè)Kurbernetes Native Java框架。
*GraalVM:JVM為了提升效率,借助JIT及時(shí)編譯技術(shù)對(duì)解釋執(zhí)行的字節(jié)碼進(jìn)行局部優(yōu)化,通過編譯器生成本地執(zhí)行代碼提升應(yīng)用執(zhí)行效率。GraalVM是Oracle實(shí)驗(yàn)室開發(fā)的新一代的面向多種語言的JVM即時(shí)編譯器,在性能以及多語言互操作性上有比較好的表現(xiàn)。與Java HotSpot VM相比,Graal借助內(nèi)聯(lián),逃逸分析以及推出優(yōu)化技術(shù)可以提升2至5倍的性能提升。
In March of 2019, after more than a year of internal development, Quarkus was introduced to the open source community. culminating in a 1.0 release within the open source community in October 2019. with a 2.0 community release in June 2021.
Among the specifications and technologies underlying Quarkus are Eclipse MicroProfile, Eclipse Vert.x, Contexts & Dependency Injection (CDI), Jakarta RESTful Web Services (JAX-RS), the Java Persistence API (JPA), the Java Transaction API (JTA), Apache Camel, and Hibernate, just to name a few.
Quarkus is also an ahead-of-time compilation (AOT) platform, optimizing code for the JVM as well as compiling to native code for improved performance. All of the underlying technologies are AOT-enabled, and Quarkus continually incorporates new AOT-enabled technologies, standards, and libraries.
Red Hat 被稱為“微服務(wù)特性(microservicility)”的內(nèi)容
https://baijiahao.baidu.com/s?id=1714420255480846215&wfr=spider&for=pc
https://www.infoq.com/articles/microservicilities-quarkus/
Kubernetes 只能覆蓋其中的三個(gè)
Quarkus 集成了 MicroProfile 規(guī)范,將企業(yè)級(jí) Java 生態(tài)系統(tǒng)轉(zhuǎn)移到了微服務(wù)架構(gòu)中。在下圖中,我們可以看到構(gòu)成 MicroProfile 規(guī)范的所有 API。其中有些 API 是基于 Jakarta EE(也就是以前的 Java EE)規(guī)范的,比如 CDI、JSON-P 和 JAX-RS,其他的則是由 Java 社區(qū)開發(fā)的。
Start
https://code.quarkus.io/
https://mvnrepository.com/artifact/io.quarkus/quarkus-maven-plugin
mvn io.quarkus:quarkus-maven-plugin:2.9.0.Final:create \
-DprojectGroupId=com.redhat.cloudnative \
-DprojectArtifactId=inventory-quarkus \
-DprojectVersion=1.0.0-SNAPSHOT \
-DclassName="com.redhat.cloudnative.InventoryResource" \
-Dextensions="quarkus-resteasy,quarkus-junit5,rest-assured,quarkus-resteasy-jsonb,quarkus-hibernate-orm-panache,quarkus-jdbc-h2"
Quarkus vs Spring
Quarkus-For-Spring-Developers-Red-Hat
https://github.com/quarkus-for-spring-developers/examples
|
Quarkus
|
Spring
|
|
|
starter
|
https://code.quarkus.io/
|
https://start.aliyun.com/
https://start.spring.io/
|
Common Quarkus extensions
Maven quarkus:list-extensions
|
Quarkus extension
|
Spring Boot Starter
|
|
quarkus-resteasy-jackson
|
spring-boot-starter-web
spring-boot-starter-webflux
|
|
quarkus-resteasy-reactive-jackson
|
spring-boot-starter-web
spring-boot-starter-webflux
|
|
quarkus-hibernate-orm-panache
|
spring-boot-starter-data-jpa
|
|
quarkus-hibernate-orm-rest-data-panache
|
spring-boot-starter-data-rest
|
|
quarkus-hibernate-reactive-panache
|
spring-boot-starter-data-r2dbc
|
|
quarkus-mongodb-panache
|
spring-boot-starter-data-mongodb
spring-boot-starter-data-mongodb-reactive
|
|
quarkus-hibernate-validator
|
spring-boot-starter-validation
|
|
quarkus-qpid-jms
|
spring-boot-starter-activemq
|
|
quarkus-artemis-jms
|
spring-boot-starter-artemis
|
|
quarkus-cache
|
spring-boot-starter-cache
|
|
quarkus-redis-client
|
spring-boot-starter-data-redis
spring-boot-starter-data-redis-reactive
|
|
quarkus-mailer
|
spring-boot-starter-mail
|
|
quarkus-quartz
|
spring-boot-starter-quartz
|
|
quarkus-oidc
|
spring-boot-starter-oauth2-resource-server
|
|
quarkus-oidc-client
|
spring-boot-starter-oauth2-client
|
|
quarkus-smallrye-jwt
|
spring-boot-starter-security
|
Spring遷移到Quarkus的工具
It can analyze an existing Spring Boot application and offer suggestions for utilizing the Quarkus
Spring Extensions best to migrate the application to Quarkus.
https://developers.redhat.com/products/mta/overview
Micronaut
https://micronaut.io/
https://launch.micronaut.io
Object Computing的一個(gè)團(tuán)隊(duì)開始重新思考如何從頭開始設(shè)計(jì) Java 框架。于是Micronaut框架誕生了,這是一個(gè)采用了不同做法的 Java 框架,它通過使用 Java 注釋將框架的組裝計(jì)算工作所轉(zhuǎn)移到了編譯階段。這完全消除了傳統(tǒng) Java 框架使用的反射、運(yùn)行時(shí)生成代理和復(fù)雜的動(dòng)態(tài)類加載。
2018 年 4 月,Micronaut 框架首次公開發(fā)布。
Spring Native
https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/
https://start.spring.io/
Eclipse Microprofile
https://start.microprofile.io
Eclipse MicroProfile 是一個(gè) Java 微服務(wù)開發(fā)的基礎(chǔ)編程模型,它致力于定義企業(yè) Java 微服務(wù)規(guī)范,MicroProfile 提供指標(biāo)、API 文檔、運(yùn)行狀況檢查、容錯(cuò)、JWT、Open API 與分布式跟蹤等能力,使用它創(chuàng)建的云原生微服務(wù)可以自由地部署在任何地方,包括 Service Mesh 架構(gòu),如 Istio。