Skip to content

a quickstart showing how to use Spring Boot, Apache Camel and Drools together with Kubernetes or OpenShift

License

Notifications You must be signed in to change notification settings

fabric8-quickstarts/spring-boot-camel-drools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring-Boot Camel-Drools QuickStart

This example demonstrates how you can use Apache Camel to integrate a Spring-Boot application running on Kubernetes or OpenShift with a remote Kie Server.

The application utilizes the Spring @ImportResource annotation to load a Camel Context definition via a src/main/resources/spring/camel-context.xml file on the classpath.

Important
This quickstart can run in 2 modes: standalone on your machine and on Kubernetes / OpenShift Cluster. Quickstart requires Java 8 or Java 11 (fuse-java-openshift-jdk11-rhel8 image is used to build in Java 11).

Kie Server Deployment

The Kie Server along with the classic hellorule example should be deployed before running the application. The example is based on the Person and Greeting facts. The Camel route will periodically add a Person fact into the remote knowledge base and retrieve a Greeting created by the rule through REST API.

To deploy the Kie server, the business automation operator is needed. Consult the Business Automation Operator Installation Guide to obtain information on how to install the operator.

Once the operator is installed, is possible to deploy the Kie Server with the hellorule example app:

$ oc create -f KieApp.yaml

On the Decision Server image, access to the rest API is restricted to authenticated users, so the same username and password combination chosen in the KieApp.yaml file must be used in the configuration of the current this quickstart.

Note: Username and password as well as the service name of the Kie Server for the current quickstart can be set in the application.properties file (especially when running this quickstart using the openshift-maven-plugin) or from the Openshift creation wizard when the S2I template is used.

Configuration through the application.properties file can also be useful when running the quickstart locally.

Deployment options

You can run this quickstart in the following modes:

  • Kubernetes / Single-node OpenShift cluster

  • Standalone on your machine

The most effective way to run this quickstart is to deploy and run the project on OpenShift.

For more details about running this quickstart on a single-node OpenShift cluster, CI/CD deployments, as well as the rest of the runtime, see the Spring Boot Runtime Guide.

Running the Quickstart on a single-node Kubernetes/OpenShift cluster

Important
You need to run this example on Container Development Kit 3.7 or OpenShift 4.11. Both of these products have suitable Fuse images pre-installed. If you run it in an environment where those images are not preinstalled follow the steps described in Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images.

A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment.

If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your quickstart there.

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the quickstart:

    $ oc new-project MY_PROJECT_NAME
  3. Change the directory to the folder that contains the extracted quickstart application (for example, my_openshift/spring-boot-camel-drools) :

    $ cd my_openshift/spring-boot-camel-drools
  4. Build and deploy the project to the OpenShift cluster:

    $ mvn clean -DskipTests oc:deploy -Popenshift
  5. In your browser, navigate to the MY_PROJECT_NAME project in the OpenShift console. Wait until you can see that the pod for the spring-boot-camel-drools has started up.

  6. On the project’s Overview page, navigate to the details page deployment of the spring-boot-camel-drool application: https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/rc/spring-boot-camel-drools-NUMBER_OF_DEPLOYMENT?tab=details.

  7. Switch to tab Logs and then see the messages sent by Camel:

    13:01:41.357 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello George!
    13:01:51.355 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Seamus!
    13:02:01.355 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:02:11.354 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:02:21.356 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!
    13:02:31.363 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!
    13:02:41.361 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Seamus!
    13:02:51.358 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!
    13:03:01.363 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello George!
    13:03:11.359 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:03:21.359 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:03:31.359 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:03:41.358 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!

Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images

A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment.

If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your quickstart there.

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the quickstart:

    $ oc new-project MY_PROJECT_NAME
  3. Configure Red Hat Container Registry authentication (if it is not configured). Follow documentation.

  4. Import base images in your newly created project (MY_PROJECT_NAME):

    $ oc import-image fuse-java-openshift:1.13 --from=registry.redhat.io/fuse7/fuse-java-openshift:1.13 --confirm
  5. Change the directory to the folder that contains the extracted quickstart application (for example, my_openshift/spring-boot-camel-drools) :

    $ cd my_openshift/spring-boot-camel-drools
  6. Build and deploy the project to the OpenShift cluster:

    $ mvn clean -DskipTests oc:deploy -Popenshift -Djkube.generator.fromMode=istag -Djkube.generator.from=MY_PROJECT_NAME/fuse-java-openshift:1.13
  7. In your browser, navigate to the MY_PROJECT_NAME project in the OpenShift console. Wait until you can see that the pod for the spring-boot-camel-drools has started up.

  8. On the project’s Overview page, navigate to the details page deployment of the spring-boot-camel-drool application: https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/rc/spring-boot-camel-drools-NUMBER_OF_DEPLOYMENT?tab=details.

  9. Switch to tab Logs and then see the messages sent by Camel:

    13:01:41.357 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello George!
    13:01:51.355 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Seamus!
    13:02:01.355 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:02:11.354 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:02:21.356 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!
    13:02:31.363 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!
    13:02:41.361 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Seamus!
    13:02:51.358 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!
    13:03:01.363 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello George!
    13:03:11.359 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:03:21.359 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:03:31.359 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Marty!
    13:03:41.358 [Camel (camel) thread #1 - timer://testRoute] INFO test-route - Hello Dave!

Running the quickstart standalone on your machine

To run this quickstart as a standalone project on your local machine:

  1. Download the project and extract the archive on your local filesystem.

  2. Build the project:

    $ cd PROJECT_DIR
    $ mvn clean package
  3. Run the service:

    $ mvn spring-boot:run
  4. See the messages sent by Camel.

About

a quickstart showing how to use Spring Boot, Apache Camel and Drools together with Kubernetes or OpenShift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages