/spring-boot-camel-infinispan

Quickstart to show Camel Infinispan component in Spring Boot

Primary LanguageJava

Spring-Boot Camel QuickStart

This quickstart demonstrates how to connect a Spring-Boot application to a JBoss Data Grid (or Infinispan) server using the Hot Rod protocol. It requires that the data grid server (or cluster) has been deployed first.

In the example, a Camel route is using the Infinispan server as idempotent repository, filtering out messages that have already been processed. Messages having a bounded random ID are created through a configurable generator. Another Camel route shows how to lookup cache entries in the Infinispan server.

Both routes use the default cache of the data grid, although this can be changed in the application.properties file. The default name for the target data grid cluster is DATAGRID_APP_HOTROD. It can be changed from the spring-boot configuration file or using the environment variable DATAGRID_SERVICE_NAME.

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

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.3 or OpenShift 3.7. 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-infinispan) :

    $ cd my_openshift/spring-boot-camel-infinispan
  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-infinispan has started up.

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

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

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-infinispan) :

    $ cd my_openshift/spring-boot-camel-infinispan
  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-infinispan has started up.

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

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

Running the quickstart standalone on your machine

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

To run the quickstart locally you’ll need to have an Infinispan 7.2.5.Final server running on your machine.

In one terminal run the following commands:

+

$ mvn clean install -Pinfinispan
$ target/infinispan-server-7.2.5.Final/bin/standalone.sh

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

  1. Build the project:

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

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