This project leverages Quarkus version 1.9.x, the Supersonic Subatomic Java Framework.
It exposes the following RESTful service endpoints using the Apache Camel Quarkus Platform extension:
/fruits
: returns a list of hard-coded fruits (name
anddescription
) in JSON format. It also allows to add afruit
through thePOST
HTTP method/legumes
: returns a list of hard-coded legumes (name
anddescription
) in JSON format./health
: returns the Camel Quarkus MicroProfile health checks/metrics
: the Camel Quarkus MicroProfile metrics
- JDK 11 installed with
JAVA_HOME
configured appropriately - Apache Maven 3.6.2+
You can run your application in dev mode that enables live coding using:
./mvnw quarkus:dev
The application can be packaged using ./mvnw package
.
It produces the camel-quarkus-http-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/camel-quarkus-http-1.0.0-SNAPSHOT-runner.jar
.
- Access to a Red Hat OpenShift cluster v3 or v4
- User has self-provisioner privilege or has access to a working OpenShift project
- Login to the OpenShift cluster
oc login ...
- Create an OpenShift project or use your existing OpenShift project. For instance, to create
camel-quarkus
oc new-project camel-quarkus-jvm --display-name="Apache Camel Quarkus Apps - JVM Mode"
- Use either the S2I binary workflow or S2I source workflow to deploy the
camel-quarkus-http
app as described below.
This leverages the Quarkus OpenShift extension and is only recommended for development and testing purposes.
./mvnw clean package -Dquarkus.kubernetes.deploy=true
[...]
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building thin jar: /Users/jeannyil/Workdata/myGit/Quarkus/upstream-quarkus-camel-demos/camel-quarkus-http/target/camel-quarkus-http-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.kubernetes.deployment.KubernetesDeploy] Kubernetes API Server at 'https://api.cluster-f7d5.sandbox81.opentlc.com:6443/' successfully contacted.
[...]
[INFO] [io.quarkus.container.image.s2i.deployment.S2iProcessor] Performing s2i binary build with jar on server: https://api.cluster-f7d5.sandbox81.opentlc.com:6443/ in namespace:camel-quarkus.
[...]
[INFO] [io.quarkus.container.image.s2i.deployment.S2iProcessor] Successfully pushed image-registry.openshift-image-registry.svc:5000/camel-quarkus/camel-quarkus-http@sha256:5cc56e5b72d56a637a163f8972ca27f90296bc265dd1d30c1c72e14a62f2ad93
[INFO] [io.quarkus.container.image.s2i.deployment.S2iProcessor] Push successful
[INFO] [io.quarkus.kubernetes.deployment.KubernetesDeployer] Deploying to openshift server: https://api.cluster-f7d5.sandbox81.opentlc.com:6443/ in namespace: camel-quarkus.
[...]
- Make sure the latest supported OpenJDK 11 image is imported in OpenShift
oc import-image --confirm openjdk-11-ubi8 \ --from=registry.access.redhat.com/ubi8/openjdk-11 \ -n openshift
- Create the
camel-quarkus-http
OpenShift application from the git repositoryoc new-app https://github.com/jeanNyil/upstream-quarkus-camel-demos.git \ --context-dir=camel-quarkus-http \ --name=camel-quarkus-http \ --image-stream="openshift/openjdk-11-ubi8"
- Follow the log of the S2I build
oc logs bc/camel-quarkus-http -f
Cloning "https://github.com/jeanNyil/upstream-quarkus-camel-demos.git" ... Commit: 70efd37c8bd29fd799dc3f4b6699aed34742afda (Initial creation) Author: Jean Armand Nyilimbibi <jean.nyilimbibi@gmail.com> Date: Fri Sep 4 13:56:39 2020 +0200 [...] Successfully pushed image-registry.openshift-image-registry.svc:5000/camel-quarkus/camel-quarkus-http-s2i@sha256:a8dfcb3c5ad978825b2b5fdf0b4a98cef1365ebb82666f27927d831e1f757761 Push successful
- Create a non-secure route to expose the
camel-quarkus-http
service outside the OpenShift clusteroc expose svc/camel-quarkus-http
- Get the OpenShift route hostname
URL="http://$(oc get route camel-quarkus-http -o jsonpath='{.spec.host}')"
- Test the
/fruits
endpointcurl -w '\n' $URL/fruits
[ { "name" : "Apple", "description" : "Winter fruit" }, { "name" : "Pineapple", "description" : "Tropical fruit" }, { "name" : "Mango", "description" : "Tropical fruit" }, { "name" : "Banana", "description" : "Tropical fruit" } ]
- Test the
/legumes
endpointcurl -w '\n' $URL/legumes
[ { "name" : "Carrot", "description" : "Root vegetable, usually orange" }, { "name" : "Zucchini", "description" : "Summer squash" } ]
- Test the
/health
endpointcurl -w '\n' $URL/health
{ "status": "UP", "checks": [ { "name": "camel-liveness-checks", "status": "UP" }, { "name": "camel-context-check", "status": "UP", "data": { "contextStatus": "Started", "name": "camel-1" } }, { "name": "camel-readiness-checks", "status": "UP" } ] }
- Test the
/health/live
endpointcurl -w '\n' $URL/health/live
{ "status": "UP", "checks": [ { "name": "camel-liveness-checks", "status": "UP" } ] }
- Test the
/health/ready
endpointcurl -w '\n' $URL/health/ready
{ "status": "UP", "checks": [ { "name": "camel-context-check", "status": "UP", "data": { "contextStatus": "Started", "name": "camel-1" } }, { "name": "camel-readiness-checks", "status": "UP" } ] }
- Test the
/metrics
endpointcurl -w '\n' $URL/metrics
[...] # HELP application_camel_context_exchanges_total The total number of exchanges for a route or Camel Context # TYPE application_camel_context_exchanges_total counter application_camel_context_exchanges_total{camelContext="camel-1"} 14.0 [...] # HELP application_camel_route_exchanges_total The total number of exchanges for a route or Camel Context # TYPE application_camel_route_exchanges_total counter application_camel_route_exchanges_total{camelContext="camel-1",routeId="fruits-restful-route"} 9.0 application_camel_route_exchanges_total{camelContext="camel-1",routeId="legumes-restful-route"} 5.0 [...]
Testing using Postman
Import the provided Postman Collection for testing: tests/Camel-Quarkus-Http.postman_collection.json
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/camel-quarkus-http-1.0.0-SNAPSHOT-runner
If you want to learn more about building native executables, please consult https://quarkus.io/guides/building-native-image.