This example demonstrates how you can use Apache Camel with Spring Boot based on a 'fabric8 Java base image'.
The quickstart uses Spring Boot to configure a little application that includes a Camel route that triggers a message every 5th second, and routes the message to a log.
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 |
You can run this quickstart in the following modes:
-
Kubernetese / 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.
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.
To deploy this quickstart to a running single-node OpenShift cluster:
-
Download the project and extract the archive on your local filesystem.
-
Log in to your OpenShift cluster:
$ oc login -u developer -p developer
-
Create a new OpenShift project for the quickstart:
$ oc new-project MY_PROJECT_NAME
-
Change the directory to the folder that contains the extracted quickstart application (for example,
my_openshift/spring-boot-camel
) :$ cd my_openshift/spring-boot-camel
-
Build and deploy the project to the OpenShift cluster:
$ mvn clean -DskipTests fabric8:deploy -Popenshift
-
In your browser, navigate to the
MY_PROJECT_NAME
project in the OpenShift console. Wait until you can see that the pod for thespring-boot-camel
has started up. -
On the project’s
Overview
page, navigate to the details page deployment of thespring-boot-camel
application:https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/rc/spring-boot-camel-NUMBER_OF_DEPLOYMENT?tab=details
. -
Switch to tab
Logs
and then see the messages sent by Camel.
To run this quickstart as a standalone project on your local machine:
-
Download the project and extract the archive on your local filesystem.
-
Build the project:
$ cd PROJECT_DIR $ mvn clean package
-
Run the service:
$ mvn spring-boot:run
-
See the messages sent by Camel.
The example includes a fabric8 arquillian Kubernetes Integration Test. Once the container image has been built and deployed in Kubernetes, the integration test can be run with:
mvn test -Dtest=*KT
The test is disabled by default and has to be enabled using -Dtest
. Integration Testing and Fabric8 Arquillian Extension provide more information on writing full fledged black box integration tests for Kubernetes.