Git Product home page Git Product logo

quarkus-example-1's Introduction

quarkus-sample project

This is a sample project for Allot. It demonstrates functionality of applications built with Quarkus framework and running on Kubernetes.

Technical Info

in development - run the database as a docker image in the host network. This way, the Java code of the Quarkus application can access the database on port 5432.

In staging - the JVM of the app and the docker image of the database will both run on the same docker private network, initiated by docker-compose.

In production - the JVM and the database will run in Kubernetes.

database

PostgreSQL running in docker image.

docker run -d --rm --name=postgresdb -p5432:5432 --env POSTGRES_PASSWORD=mypassword --volume /home/evyatar/work/quarkus/news-quarkus/src/main/resources/init:/docker-entrypoint-initdb.d/ postgres:11-alpine

This specific docker image of PostgreSQL has the following defaults: database: postgres username: postgres

the file setup.sql is used for initializing SQL statements. In addition, Hibernate automatically creates the tables of the entities.

This project uses Quarkus, the Supersonic Subatomic Java Framework.

If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .

Running the application in dev mode

You can run your application in dev mode that enables live coding using:

./mvnw quarkus:dev

but before that, you must run the docker of the database as explained above.

Running the application in "staging" mode with docker-compose

docker-compose can be used to start all services (in this example: the database and the app) in docker on the same ("private") network.

To do that, use the docker-compose.yml and issue the command docker-compose up

(this builds the docker of the quarkus-app:)

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
mvn package -DskipTests
docker build -f src/main/docker/Dockerfile.jvm -t quarkus-sample-jvm .
docker-compose up

You will see in the terminal window the logs from the quarkus app! Hit Ctrl+C to stop all the services (in this case only 2 - the database and the app)

Note that for this to work, you should change in application.properties the jdbc url:

quarkus.datasource.url = jdbc:postgresql://postgres:5432/postgres (the first "postgres" is the name of the service in docker-compose.yml. the second "postgres" is the name of the schema inside the DB. In other environment (for example: dev), the jdbc url could be quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/mydatabase)

Metrics

from command line, use curl -H "Accept: application/json" http://localhost:8080/metrics/application to see metrics (of application). base, vendor.

curl localhost:8080/person/age/average

http --json http://localhost:8080/metrics/vendor | grep 'hibernate' | grep orm

http --json http://localhost:8080/metrics | grep method=averageAge

Config

in Java code: @ConfigProperty(defaultValue = "World!", name = "my.name") String name ;

in docker-compose.yml added: environment: MY_NAME: "Evyatar"

docker-compose up then http http://localhost:8080/ex/hello

Packaging and running the application

The application can be packaged using ./mvnw package. It produces the quarkus-sample-1.0.0-SNAPSHOT-runner.jar file in the /target directory. Be aware that it’s not an über-jar as the dependencies are copied into the target/lib directory.

The application is now runnable using java -jar target/quarkus-sample-1.0.0-SNAPSHOT-runner.jar.

Creating a native executable

You can create a native executable using: ./mvnw package -Pnative.

Or, if you don't have GraalVM installed, you can run the native executable build in a container using: ./mvnw package -Pnative -Dquarkus.native.container-build=true.

You can then execute your native executable with: ./target/quarkus-sample-1.0.0-SNAPSHOT-runner

If you want to learn more about building native executables, please consult https://quarkus.io/guides/building-native-image.

quarkus-example-1's People

Contributors

evyatark avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.