Aleksy
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Quarkus Article 1 ## Cloud Native ## Quarkus Quarkus to full-stack framework dla Javy, który jest open sourcowym projektem stworzonym przez Red Hat. Jego historia jest krótka, pierwszy release 0.0.1 miał miejsce pod koniec 2018 roku, lecz pomimo krótkiej historii framework szybko się rozwija. Przez twórców jest definiowany jako narzędzie które pozwoli Javie stać się wydajną platformą dla środowisk serverlessowych, chmurowych i Kubernetesa, jak również dzięki zastosowaniu GraalVM umożliwi natywną kompilacje aplikacji. ### Alternatywy Spring Boot jest najstarszą jak również najbardziej rozpowszechnioną alternatywą na rynku. Rozwijany przez Pivotal Team, "nadbudowany" na Spring Framework oferuje znacznie szybsze tworzenie, konfigurowanie i uruchamianie mikroserwisowych aplikacji. Micronaut to full-stack framework przeznaczony do tworzenia aplikacji mikroserwisowych oraz serverlessowych, rozwijany przez twórców Grails. Dostępny na rynku od 2018 roku. ### Dlaczego wybraliśmy Quarkusa? Pomimo swojej krótkiej obecności na rynu, szybko się rozwija oraz jest o nim coraz głośniej na wielu prezentacjach branżowych. To wzbudziło nasze zainteresowanie i sprawiło że posnowiliśmy mu się lepiej przyjrzeć. Poza aspektem nowości przyciąga on również innymi cechami: #### Supersonic Subatomic Java Framework obiecuje pozwolić na niezwykle szybki start aplikacji oraz krótki czas obsłużenia pierwszego requestu(Supersonic). Ma również zostać zniwelowane zużycie pamięci, a w przypadku natywnej kompilacji nawet o 86%(subatomic) #### Hot replace Oczywiści `Hot replace` nie jest żadną nowością. Spring Boot również to umożliwia dzięki zastosowaniu `spring-boot-devtools`. Lecz rozwiązanie to ma problemy, w przeciwieństwie do Quarkusa, gdzie wszystko działa szybko i bez zastrzeżeń. #### Deweloper experience Jak podkreślają twórcy, framework ma zmniejszyć czas potrzebny na dewelopment, uprzyjemnić ten proces, a tym samym nie wymagać od programistów nauki wielu nowych technologii gdyż bazuje on na znanych rozwiązaniach. Potwierdzenie tych słów można znaleźć w [artykule](https://quarkus.io/blog/vodafone-greece-replaces-spring-boot) opisującym przejście Vodafone Greece ze Spring Boota na Quarkusa “30 to 40% better developer productivity vis-a-vis Spring Boot, and this is for an ex-Spring Boot developer”. #### Quarkus na GraalVM(GraalVM, co to jest i co to nam daje) Tu GraalVM ## Jak zacząć z Quarkusem? Generowanie nowego projektu nie jest niczym nowym w stosunku do Spring Boota bądź Micronauta. Możemy wykorzystać webowy generator dostępny pod adrese: https://code.quarkus.io/, bądź skorzystać z plaginu dostępnego dla następujących środowisk: - Eclipse - Visual Studio Code - IntelliJ Na potrzeby artykułu będziemy korzystać ze zintegrowanego z IntelliJem pluginu: ![](https://i.imgur.com/7ptS7nV.png) Na początek względem ustawień domyślnyh zmienimy jedynie nazwę naszego projektu: ![](https://i.imgur.com/H5Ja4wF.png) Na tym etapie wybieramy tylko jedną dodatkową zależność, RESTEasy Jackson, reszta zostanie dodane później. Dodajemy RESTEasy Jackson, aby umożliwć automatyczną serializacje oraz deserializację obiektów. ![](https://i.imgur.com/7Oewcyh.png) Gotowe, projekt został wygenerowany ![](https://i.imgur.com/753fraI.png) W strukturze projektu znajdują się: - `ExampleResource` z `/hello` endpoint - `ExampleResourceTest` weryfikujący czy endpoint `/hello` zwraca `hello` - przykładowe Dockerfile - pom Co ciekawego w `pom`? Tutaj znajduje się import Quarkus BOM, który rozwiąże za nas wersje wszystkich quarkusowych zależności. Dodatkowo wśród pluginów mamy `quarkus-maven-plugin`, który jest dostarcza tryb deweloperski, oraz odpowiada za zbudowanie aplikacji. ```xml <dependencyManagement> <dependencies> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-bom</artifactId> <version>${quarkus.platform.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>io.quarkus</groupId> <artifactId>quarkus-maven-plugin</artifactId> <version>${quarkus-plugin.version}</version> <executions> <execution> <goals> <goal>generate-code</goal> <goal>generate-code-tests</goal> <goal>build</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ``` Teraz uruchomy naszą aplikację za pomocą komendy ```shell ./mvnw compile quarkus:dev ``` Aplikacja zostałą uruchomiona poprawnie, co prezentują poniższe logi. Dzięki `Hot replace` dostępnemu w ramach trybu deweloperskiego w trakcje implementacji nie będzimey musieli ręcznie restartować aplikacji. ```shell __ ____ __ _____ ___ __ ____ ______ --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \ --\___\_\____/_/ |_/_/|_/_/|_|\____/___/ 2020-10-04 20:21:15,589 INFO [io.quarkus] (Quarkus Main Thread) getting-started 1.0-SNAPSHOT on JVM (powered by Quarkus 1.8.1.Final) started in 2.216s. Listening on: http://0.0.0.0:8080 2020-10-04 20:21:15,591 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated. 2020-10-04 20:21:15,591 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy, resteasy-jackson] ``` W celu pokazania jak prosto można dewelopować wykorzystując Quarkusa oraz jak przyjemnie pracuje się z hot replace, stworzymy prostą aplikacje. Aplikacja będzie pozwalała na pobieranie oraz zapisywanie użytkowników do bazy danych PostgresSql. Na początek potrzebujemy dodać do projektu parę zależności, w tym celu zmodyfikujemy ręcznie pom, jak również wykorzystamy `quarkus-maven-plugin`. Pierwszą z zależności dodamy po przez ręczną edycję poma: ```xml <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> </dependency> ``` Następną wykorzystując maven plugin: ```shell ./mvnw quarkus:add-extension -Dextensions="io.quarkus:quarkus-hibernate-orm-panache" ``` Oczywiście nie musimy znać wszystkich zaleźności na pamięć, możemy wypisać wszystkie dostępne w następujący sposób: ```shell ./mvnw quarkus:list-extensions ``` Innym sposobem jest sprawdzenie dostępnych zależności na stronie https://code.quarkus.io/ Możemy również ponownie wykorzystać komędę dodającą zaleźność, ale tym razem zamiast podawać w całości `groupId` oraz `artifactId`, możemy jedynie podać fragment nazwy zaleźności ```shell ./mvnw quarkus:add-extension -Dextensions=postgresql ``` ![](https://i.imgur.com/Hfe0NUB.png) Jak widać komenda zakończyłą się niepowodzeniem, wynika to z tego, że z postgresql powiązane są dwie zależności, nas interesuje `io.quarkus:quarkus-jdbc-postgresql`, więc tym razem doprecyzuje: ```shell ./mvnw quarkus:add-extension -Dextensions=jdbc-postgresql ``` Gotowe. Wszystkie zależności zostały poprawnie dodane, a aplikacja dokonała hot realod po dodaniu każdej z nich. W przypadku dodawania/usuwania zaleźności hot reaload wykonuje się w następstwie zmian wramach poma. Inaczej sytuacja ma się w przypadku zmian w kodzie, ale o tym za chwile. Do `application.properties` dodajemy propertiesy konieczne do połączenia z naszą bazą ```json quarkus.datasource.db-kind=postgresql quarkus.datasource.username=yhleaubv quarkus.datasource.password=wpCOwJmPVcsak3eQqtVMYxnicn0ls7I8 quarkus.datasource.jdbc.url=jdbc:postgresql://kandula.db.elephantsql.com:5432/yhleaubv quarkus.hibernate-orm.database.generation=drop-and-create ``` Tworzymy encje, rozszerzając `PanacheEntity`: ```java @Getter @Setter @Entity @Table(name = "users") public class User extends PanacheEntity { private String name; private String lastname; } ``` `Hibernate ORM with Panache` pozwala nam na rozszerzenie naszej encji wykorzystując `PanacheEntity` lub `PanacheEntityBase`, dając nam dostęp do operacji na bazie typu find/delete/persiste wykorzystując `HQL` bez potrzeby wstrzykiwania `repository` `PanacheEntity` rozszerza `PanacheEntityBase` dodając ```java @Id @GeneratedValue public Long id; ``` Następnie tworzymy kontroler: ``` java @Path("/users") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public class UserController { @GET public List<User> getUsersByName(@QueryParam("name") String name) { return User.find("name = ?1", name).list(); } @POST @Transactional public Response createUser(User user) { User.persist(user); return Response.ok().build(); } } ``` W celu zinicjowania początkowego stanu bazy dodamy skryt `import.sql` do `resources/`. ```sql insert into users(id, name, lastname) values(1, 'Jacek', 'Kowalski'); insert into users(id, name, lastname) values(2, 'Piotr', 'Nowak'); ``` Implementacja aplikacji została zakończona, możemy wykonać zapytanie pod adres `http://localhost:8080/users?name=Jacek` w odpowiedzi otrzymamy JSON: ```json [ { "id": 1, "name": "Jacek", "lastname": "Kowalski" } ] ``` ale to nie wszystko, w momencie requestu, Quarkus był świadom zmian które zaszły w kodzie, więc najpierw dokonał hot replace, a następnie obsłużył zapytanie. ``` 2020-10-04 20:31:58,834 INFO [io.qua.dep.dev.RuntimeUpdatesProcessor] (vert.x-worker-thread-3) Hot replace total time: 3.792s ``` Proces implementacji w całości odbył się bez konieczności ręcznego restartowania aplikacji. ### JVM vs Native #### JVM ```shell mvn clean package [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 26.991 s [INFO] Finished at: 2020-10-04T20:58:10+02:00 [INFO] ------------------------------------------------------------------------ ``` ```shell java -Xms32m -jar target/quarkus-getting-started-1.0-SNAPSHOT-runner.jar __ ____ __ _____ ___ __ ____ ______ --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \ --\___\_\____/_/ |_/_/|_/_/|_|\____/___/ 2020-10-04 20:59:58,368 INFO [io.quarkus] (main) quarkus-getting-started 1.0-SNAPSHOT on JVM (powered by Quarkus 1.8.1.Final) started in 3.224s. Listening on: http://0.0.0.0:8080 2020-10-04 20:59:58,370 INFO [io.quarkus] (main) Profile prod activated. 2020-10-04 20:59:58,370 INFO [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, jdbc-postgresql, mutiny, narayana-jta, resteasy, resteasy-jackson, smallrye-context-propagation] ``` ```shell PS C:\> jps 19264 quarkus-getting-started-1.0-SNAPSHOT-runner.jar ``` ```shell PS C:\> wmic process where processid=19264 get WorkingSetSize WorkingSetSize 148848640 ``` #### Native ```shell cmd /c 'call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat" && mvn package -Pnative' [INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 254110ms [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 03:42 min [INFO] Finished at: 2020-10-04T21:26:21+02:00 [INFO] ------------------------------------------------------------------------ ``` ```shell ./target/quarkus-getting-started-1.0-SNAPSHOT-runner __ ____ __ _____ ___ __ ____ ______ --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \ --\___\_\____/_/ |_/_/|_/_/|_|\____/___/ 2020-10-04 21:37:43,845 INFO [io.quarkus] (main) quarkus-getting-started 1.0-SNAPSHOT native (powered by Quarkus 1.8.1.Final) started in 0.523s. Listening on: http://0.0.0.0:8080 2020-10-04 21:37:43,845 INFO [io.quarkus] (main) Profile prod activated. 2020-10-04 21:37:43,846 INFO [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, jdbc-postgresql, mutiny, narayana-jta, resteasy, resteasy-jackson, smallrye-context-propagation] ``` ```shell PS C:\>Get-Process -Name quarkus* Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ----------- 255 58 75208 100296 0,09 19600 1 quarkus-getting-started-1.0-SNAPSHOT-runner ``` ```shell PS C:\>wmic process where processid=19600 get WorkingSetSize WorkingSetSize 102256640 ``` Przed dokonaniem pomariu zostały wykonane identyczne zapytania do aplikacji. | | JVM | Native | Różnica | | -------- | -------- | --- | -------- | | Czas startu(s) | 3.224 | 0.523| 83% | | Pamięć(MB) | 141.95 | 97.52 | 31% | Czas startu aplikacji spadł o 83%, natomiast zużycie pamięci o 31%. ## Bibliografia https://www.redhat.com/en/topics/cloud-native-apps/what-is-quarkus https://quarkus.io/blog/vodafone-greece-replaces-spring-boot/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully