{"id":74793,"date":"2020-03-20T20:42:19","date_gmt":"2020-03-20T17:42:19","guid":{"rendered":"https:\/\/prohoster.info\/blog\/administrirovanie\/quarkus-sverhzvukovaya-subatomnaya-java-kratkij-obzor-frejmvorka"},"modified":"2020-03-20T20:42:19","modified_gmt":"2020-03-20T17:42:19","slug":"quarkus-sverhzvukovaya-subatomnaya-java-kratkij-obzor-frejmvorka","status":"publish","type":"post","link":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/quarkus-sverhzvukovaya-subatomnaya-java-kratkij-obzor-frejmvorka","title":{"rendered":"Quarkus \u2014 supersonic subatomic Java. A brief overview of the framework","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><img decoding=\"async\" alt=\"Quarkus \u2014 supersonic subatomic Java. A brief overview of the framework\" src=\"\/wp-content\/uploads\/2020\/03\/b40e193b4a696206aad8b08a5e4795a1.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<h3 id=\"vvedenie\">Introduction<\/h3>\n<p><\/p>\n<p>On March seventh, RedHat (soon to be IBM) <noindex><a rel=\"nofollow\" href=\"https:\/\/developers.redhat.com\/blog\/2019\/03\/07\/quarkus-next-generation-kubernetes-native-java-framework\/\">introduced<\/a><\/noindex> introduces a new framework \u2014 <noindex><a rel=\"nofollow\" href=\"https:\/\/quarkus.io\/\">Quarkus<\/a><\/noindex>. According to the developers, this framework is based on GraalVM and OpenJDK HotSpot and is intended for Kubernetes. The Quarkus stack includes: JPA\/Hibernate, JAX-RS\/RESTEasy, Eclipse Vert.x, Netty, Apache Camel, Kafka, Prometheus, and others.<\/p>\n<p><\/p>\n<p>The goal of its creation is to make Java the leading platform for deployment in Kubernetes and development of serverless applications, providing developers with a unified approach for programming in both reactive and imperative styles.<\/p>\n<p><\/p>\n<p>If we look at <noindex><a rel=\"nofollow\" href=\"https:\/\/dzone.com\/articles\/classification-of-development-frameworks-for-enter\"><u>this<\/u><\/a><\/noindex> classifying frameworks, Quarkus falls somewhere between \"Aggregators\/Code Generators\" and \"High-level fullstack frameworks.\" It is more than just an aggregator, but it doesn't quite reach the level of a full-stack framework, as it is specifically designed for backend development.<\/p>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<p>Very high application startup speed and low memory consumption are promised. Here are the data from the developer\u2019s website:<\/p>\n<p><\/p>\n<p>Time from start to first response (s):<\/p>\n<p><\/p>\n<p>Configuration<br \/>\nREST<br \/>\nREST+JPA<\/p>\n<p>Quarkus+GraalVM<br \/>\n0.014<br \/>\n0.055<\/p>\n<p>Quarkus+OpenJDK<br \/>\n0.75<br \/>\n2.5<\/p>\n<p>Traditional Cloud Native Stack*<br \/>\n4.3<br \/>\n9.5<\/p>\n<p><\/p>\n<p>Memory consumption (Mb):<\/p>\n<p><\/p>\n<p>Configuration<br \/>\nREST<br \/>\nREST+JPA<\/p>\n<p>Quarkus+GraalVM<br \/>\n13<br \/>\n35<\/p>\n<p>Quarkus+OpenJDK<br \/>\n74<br \/>\n130<\/p>\n<p>Traditional Cloud Native Stack*<br \/>\n140<br \/>\n218<\/p>\n<p><\/p>\n<p>Impressive, isn't it?<\/p>\n<p><\/p>\n<p>*<em>I couldn't find any information about this technology stack, one might assume it's some kind of Spring Boot with additional features.<\/em>.<\/p>\n<p><\/p>\n<h3 id=\"hello-world\">Hello World!<\/h3>\n<p><\/p>\n<p>The simplest application written in Quarkus would look like this:<\/p>\n<p><\/p>\n<pre><code class=\"java\">@Path(\"\/hello\")\npublic class GreetingResource {\n\n   @GET\n   @Produces(MediaType.TEXT_PLAIN)\n   public String hello() {\n       return \"hello\";\n   }\n}<\/code><\/pre>\n<p><\/p>\n<p>This is literally one class and it's enough! You can run the application using Maven in development mode:<\/p>\n<p><\/p>\n<pre><code class=\"plaintext\">mvn compile quarkus:dev\n\u2026\n$ curl http:\/\/localhost:8080\/hello\nhello<\/code><\/pre>\n<p><\/p>\n<p>The difference from a regular application is that there is no Application class! Quarkus supports hot reload, allowing you to change the application without restarting it, making development even faster. <\/p>\n<p><\/p>\n<p>What's next? You can add a service to the controller using the annotation <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/users\/inject\/\" class=\"user_link\">Inject<\/a><\/noindex>. The service code:<\/p>\n<p><\/p>\n<pre><code class=\"java\">@ApplicationScoped\npublic class GreetingService {\n\n   public String greeting(String name) {\n       return \"Hello \" + name + \"!\";\n   }\n}<\/code><\/pre>\n<p><\/p>\n<p>Controller:<\/p>\n<p><\/p>\n<pre><code class=\"java\">@Path(\"\/hello\")\npublic class GreetingResource {\n\n   @Inject\n   GreetingService service;\n\n   @GET\n   @Produces(MediaType.TEXT_PLAIN)\n   @Path(\"\/{name}\")\n   public String greeting(@PathParam(\"name\") String name) {\n       return service.greeting(name);\n   }\n}<\/code><\/pre>\n<p><\/p>\n<pre><code class=\"plaintext\">$ curl http:\/\/localhost:8080\/hello\/developer\nHello developer!<\/code><\/pre>\n<p><\/p>\n<p>Note that Quarkus uses standard annotations from familiar frameworks \u2014 CDI and JAX-RS. There's nothing new to learn if you have worked with CDI and JAX-RS before, of course. <\/p>\n<p><\/p>\n<h3 id=\"rabota-s-bazoy-dannyh\">Working with the database<\/h3>\n<p><\/p>\n<p>Hibernate and standard JPA annotations are used for entities. As with REST controllers, a minimal amount of code is required. It is sufficient to specify dependencies in the build file and place the annotations. <code>@Entity<\/code> and configure the datasource in application.properties. <\/p>\n<p><\/p>\n<p>That's all. No sessionFactory, persistence.xml, or other service files are needed. We only write the code that is necessary. However, if necessary, a persistence.xml file can be created to configure the ORM layer more finely. <\/p>\n<p><\/p>\n<p>Quarkus supports caching of entities, collections for one-to-many relationships, as well as queries. At first glance, it looks great, but this <em>is local<\/em> caching for a single Kubernetes node. That is, caches of different nodes are not synchronized with each other. I hope this is temporary. <\/p>\n<p><\/p>\n<h3 id=\"asinhronnoe-vypolnenie-koda\">Asynchronous code execution<\/h3>\n<p><\/p>\n<p>As mentioned above, Quarkus also supports reactive programming style. The code of the previous application can be rewritten in another form.<\/p>\n<p><\/p>\n<pre><code class=\"java\">@Path(\"\/hello\")\npublic class GreetingResource {\n\n   @GET\n   @Produces(MediaType.TEXT_PLAIN)\n   @Path(\"\/{name}\")\n   public CompletionStage greeting(@PathParam(\"name\") String name) {\n       return CompletableFuture.supplyAsync(() -&gt; {\n           return \"Hello \" + name + \"!\";\n       });\n   }\n}<\/code><\/pre>\n<p><\/p>\n<p>Asynchronous code can also be moved to a service, and the result will be the same. <\/p>\n<p><\/p>\n<h3 id=\"testirovanie\">Testing<\/h3>\n<p><\/p>\n<p>Tests for Quarkus applications can be written using JUnit4 or JUnit5. Below is an example test for the endpoint, written using RestAssured, but another framework can also be used: <\/p>\n<p><\/p>\n<pre><code class=\"java\">@QuarkusTest\npublic class GreetingResourceTest {\n\n   @Test\n   public void testGreetingEndpoint() {\n       String uuid = UUID.randomUUID().toString();\n       given()\n         .pathParam(\"name\", uuid)\n         .when().get(\"\/hello\/{name}\")\n         .then()\n           .statusCode(200)\n           .body(is(\"Hello \" + uuid + \"!\"));\n   }\n}<\/code><\/pre>\n<p><\/p>\n<p>The @QuarkusTest annotation instructs to start the application before running the tests. Otherwise, it is familiar code for all developers. <\/p>\n<p><\/p>\n<h3 id=\"platformo-zavisimoe-prilozhenie\">Platform-dependent application<\/h3>\n<p><\/p>\n<p>Since Quarkus is tightly integrated with GraalVM, it is indeed possible to generate platform-dependent code. To do this, you need to install GraalVM and set the GRAALVM_HOME environment variable. Then <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/quarkusio\/quarkus-quickstarts\/blob\/fae88eaab10ed4d68ac44e0b8b7416e631b8a6f9\/getting-started-knative\/pom.xml#L105\">define a profile for the build<\/a><\/noindex> and specify it when building the application:<\/p>\n<p><\/p>\n<pre><code class=\"java\">mvn package -Pnative<\/code><\/pre>\n<p><\/p>\n<p>Interestingly, the generated application can be tested. This is important because the execution of native code may differ from execution on the JVM. The @SubstrateTest annotation runs platform-dependent code of the application. Reusing existing test code can be accomplished through inheritance; thus, the code for testing a platform-dependent application would look like this:<\/p>\n<p><\/p>\n<pre><code class=\"java\">@SubstrateTest\npublic class GreetingResourceIT extends GreetingResourceTest {\n\n}<\/code><\/pre>\n<p><\/p>\n<p>The generated image can be packaged in Docker and run in Kubernetes or OpenShift, as detailed in <noindex><a rel=\"nofollow\" href=\"https:\/\/quarkus.io\/guides\/kubernetes-guide\">the instructions<\/a><\/noindex>.<\/p>\n<p><\/p>\n<h3 id=\"instrumentariy\">Toolset<\/h3>\n<p><\/p>\n<p>The Quarkus framework can be used with Maven and Gradle. Maven is fully supported, unlike Gradle. Unfortunately, at present, Gradle does not support the generation of an empty project; detailed information can be found on the website. <noindex><a rel=\"nofollow\" href=\"https:\/\/quarkus.io\/guides\/gradle-tooling.html\">textbook<\/a><\/noindex>.<\/p>\n<p><\/p>\n<h3 id=\"rasshireniya\">Extensions<\/h3>\n<p><\/p>\n<p>Quarkus is an extensible framework. Currently, there are about <noindex><a rel=\"nofollow\" href=\"https:\/\/quarkus.io\/extensions\/\">40 extensions<\/a><\/noindex>, which add various functionalities \u2014 from supporting <noindex><a rel=\"nofollow\" href=\"https:\/\/quarkus.io\/extensions\/#migration\">the Spring DI container<\/a><\/noindex> and <noindex><a rel=\"nofollow\" href=\"https:\/\/quarkus.io\/extensions\/#integration\">to Apache Camel<\/a><\/noindex> to logging and publishing metrics for running services. There is already an extension to support writing applications in Kotlin, in addition to Java. <\/p>\n<p><\/p>\n<h2 id=\"zaklyuchenie\">Conclusion<\/h2>\n<p><\/p>\n<p>In my opinion, Quarkus is very much in line with current trends. Backend development is becoming simpler and simpler, and this framework further simplifies and accelerates service development, adding native support for Docker and Kubernetes. A huge plus is the built-in support for GraalVM and the generation of platform-dependent images, allowing services to start up really quickly and occupy little memory. This is crucial in our time of widespread interest in microservices and serverless architecture.<\/p>\n<p><\/p>\n<p>The official website is \u2014 <noindex><a rel=\"nofollow\" href=\"https:\/\/quarkus.io\/\">quarkus.io<\/a><\/noindex>. Project examples for quick start are already available on <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/quarkusio\/quarkus-quickstarts\">GitHub<\/a><\/noindex>.\n<\/p>\n<p>Source: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/company\/haulmont\/blog\/443242\/\">habr.com<\/a> <\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0421\u0435\u0434\u044c\u043c\u043e\u0433\u043e \u043c\u0430\u0440\u0442\u0430 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f RedHat (\u0432\u0441\u043a\u043e\u0440\u0435 \u2014 IBM) \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u043d\u043e\u0432\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u2014 Quarkus. \u041f\u043e \u0441\u043b\u043e\u0432\u0430\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u044d\u0442\u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0431\u0430\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 GraalVM \u0438 OpenJDK HotSpot \u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f Kubernetes. \u0421\u0442\u0435\u043a Quarkus \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f: JPA\/Hibernate, JAX-RS\/RESTEasy, Eclipse Vert.x, Netty, Apache Camel, Kafka, Prometheus \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u0426\u0435\u043b\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u2014 \u0441\u0434\u0435\u043b\u0430\u0442\u044c Java \u043b\u0438\u0434\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u043e\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0432 Kubernetes [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":74794,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-74793","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/quarkus-sverhzvukovaya-subatomnaya-java-kratkij-obzor-frejmvorka\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47Quarkus \u2014 \u0441\u0432\u0435\u0440\u0445\u0437\u0432\u0443\u043a\u043e\u0432\u0430\u044f \u0441\u0443\u0431\u0430\u0442\u043e\u043c\u043d\u0430\u044f Java. \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 | ProHoster\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/quarkus-sverhzvukovaya-subatomnaya-java-kratkij-obzor-frejmvorka\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-03-20T17:42:19+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-03-20T17:42:19+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Quarkus \u2014 supersonic subatomic Java. A brief overview of the framework | ProHoster","description":"","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/quarkus-sverhzvukovaya-subatomnaya-java-kratkij-obzor-frejmvorka","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47Quarkus \u2014 \u0441\u0432\u0435\u0440\u0445\u0437\u0432\u0443\u043a\u043e\u0432\u0430\u044f \u0441\u0443\u0431\u0430\u0442\u043e\u043c\u043d\u0430\u044f Java. \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 | ProHoster","og:url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/quarkus-sverhzvukovaya-subatomnaya-java-kratkij-obzor-frejmvorka","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2020-03-20T17:42:19+00:00","article:modified_time":"2020-03-20T17:42:19+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"74793","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":null,"breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 18:07:28","updated":"2022-09-30 18:17:47","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/74793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=74793"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/74793\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media\/74794"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=74793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=74793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=74793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}