Skip to content

Latest commit

 

History

History

camel-quarkus-http

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Camel-Quarkus-Http

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 and description) in JSON format. It also allows to add a fruit through the POST HTTP method
  • /legumes : returns a list of hard-coded legumes (nameand description) in JSON format.
  • /health : returns the Camel Quarkus MicroProfile health checks
  • /metrics : the Camel Quarkus MicroProfile metrics

Prerequisites

  • JDK 11 installed with JAVA_HOME configured appropriately
  • Apache Maven 3.6.2+

Running the application in dev mode

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

./mvnw quarkus:dev

Packaging and running the application locally

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.

Packaging and running the application on Red Hat OpenShift

Pre-requisites

  • Access to a Red Hat OpenShift cluster v3 or v4
  • User has self-provisioner privilege or has access to a working OpenShift project
  1. Login to the OpenShift cluster
    oc login ...
  2. 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"
  3. Use either the S2I binary workflow or S2I source workflow to deploy the camel-quarkus-http app as described below.

OpenShift S2I binary workflow

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.
[...]

OpenShift S2I source workflow (recommended for PRODUCTION use)

  1. 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
  2. Create the camel-quarkus-http OpenShift application from the git repository
    oc 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"
  3. 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
  4. Create a non-secure route to expose the camel-quarkus-http service outside the OpenShift cluster
    oc expose svc/camel-quarkus-http

Testing the application on OpenShift

  1. Get the OpenShift route hostname
    URL="http://$(oc get route camel-quarkus-http -o jsonpath='{.spec.host}')"
  2. Test the /fruits endpoint
    curl -w '\n' $URL/fruits
    [ {
        "name" : "Apple",
        "description" : "Winter fruit"
    }, {
        "name" : "Pineapple",
        "description" : "Tropical fruit"
    }, {
        "name" : "Mango",
        "description" : "Tropical fruit"
    }, {
        "name" : "Banana",
        "description" : "Tropical fruit"
    } ]
  3. Test the /legumes endpoint
    curl -w '\n' $URL/legumes
    [ {
        "name" : "Carrot",
        "description" : "Root vegetable, usually orange"
    }, {
        "name" : "Zucchini",
        "description" : "Summer squash"
    } ]
  4. Test the /health endpoint
    curl -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"
            }
        ]
    }
  5. Test the /health/live endpoint
    curl -w '\n' $URL/health/live
    {
        "status": "UP",
        "checks": [
            {
                "name": "camel-liveness-checks",
                "status": "UP"
            }
        ]
    }
  6. Test the /health/ready endpoint
    curl -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"
            }
        ]
    }
  7. Test the /metrics endpoint
    curl -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 Camel-Quarkus-Http.postman_collection.png

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/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.