This is a minimal CRUD service exposing a couple of endpoints over REST, with a front-end based on Angular so you can play with it from your browser.
While the code is surprisingly simple, under the hood this is using:
- RESTEasy to expose the REST endpoints
- Hibernate Reactive to perform the CRUD operations on the database
- A PostgreSQL database; see below to run one via Docker
- ArC, the CDI inspired dependency injection tool with zero overhead
To compile and run this demo you will need:
- JDK 1.8+
- GraalVM
In addition, you will need either a PostgreSQL database, or Docker to run one.
Make sure that both the GRAALVM_HOME
and JAVA_HOME
environment variables have
been set, and that a JDK 1.8+ java
command is on the path.
See the Building a Native Executable guide for help setting up your environment.
Launch the Maven build on the checked out sources of this demo:
./mvnw install
Make sure you have a PostgreSQL instance running. To set up a PostgreSQL database with Docker:
docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name quarkus_test -e POSTGRES_USER=quarkus_test -e POSTGRES_PASSWORD=quarkus_test -e POSTGRES_DB=quarkus_test -p 5432:5432 postgres:10.5
Connection properties for the Agroal datasource are defined in the standard Quarkus configuration file,
src/main/resources/application.properties
.
The Maven Quarkus plugin provides a development mode that supports live coding. To try this out:
./mvnw quarkus:dev
In this mode you can make changes to the code and have the changes immediately applied, by just refreshing your browser.
Hot reload works even when modifying your JPA entities. Try it! Even the database schema will be updated on the fly.
When you're done iterating in developer mode, you can run the application as a conventional jar file.
First compile it:
./mvnw install
Then run it:
java -jar ./target/hibernate-reactive-quickstart-1.0-SNAPSHOT-runner.jar
Have a look at how fast it boots. Or measure total native memory consumption...
You can also create a native executable from this application without making any source code changes. A native executable removes the dependency on the JVM: everything needed to run the application on the target platform is included in the executable, allowing the application to run with minimal resource overhead.
Compiling a native executable takes a bit longer, as GraalVM performs additional
steps to remove unnecessary codepaths. Use the native
profile to compile a
native executable:
./mvnw install -Dnative
After getting a cup of coffee, you'll be able to run this binary directly:
./target/hibernate-reactive-quickstart-1.0-SNAPSHOT-runner
Please brace yourself: don't choke on that fresh cup of coffee you just got.
Now observe the time it took to boot, and remember: that time was mostly spent to generate the tables in your database and import the initial data.
Next, maybe you're ready to measure how much memory this service is consuming.
N.B. This implies all dependencies have been compiled to native; that's a whole lot of stuff: from the bytecode enhancements that Hibernate ORM applies to your entities, to the lower level essential components such as the PostgreSQL JDBC driver, the Undertow webserver.
Navigate to:
http://localhost:8080/index.html
Have fun, and join the team of contributors!
This section provides extra information for running both the database and the demo on Kubernetes. As well as running the DB on Kubernetes, a service needs to be exposed for the demo to connect to the DB.
Then, rebuild demo docker image with a system property that points to the DB.
-Dquarkus.datasource.reactive.url=jdbc:postgresql://<DB_SERVICE_NAME>/quarkus_test