Chapter 7. Setting up Spring Boot applications for HawtIO Online with Jolokia Note If stopping a Camel route is changing the health status to DOWN and triggering a pod restart by OpenShift, a possible solution to avoid this behavior is to set: camel.routecontroller.enabled = true It will enable the supervised route controller so that the route will be with status Stopped and the overall status of the health check is UP . This section describes the enabling of monitoring of a Spring Boot application by HawtIO. It starts from first principles in setting up a simple example application. Note This application runs on OpenShift and is discovered and monitored by HawtIO online. If you already have a Spring Boot application implemented, skip to Section 7.2, "Adding Jolokia Starter dependency to the application" . Note The following is based on the jolokia sample application in the Apache Camel Spring-Boot examples repository. Prerequisites Maven has been installed and mvn is available on the Command-line (CLI). 7.1. Setting up a sample Spring Boot application To create a new Spring Boot application, you can either create the maven project directory structure manually, or execute an archetype to generate the scaffolding for a standard java project, which you can customize for individual applications. Customize these values as needed: archetypeVersion 4.8.0.redhat-00022 groupId io.hawtio.online.examples artifactId hawtio-online-example-camel-springboot-os version 1.0.0 Run the maven archetype: mvn archetype:generate \ -DarchetypeGroupId=org.apache.camel.archetypes \ -DarchetypeArtifactId=camel-archetype-spring-boot \ -DarchetypeVersion=4.8.0.redhat-00022 \ -DgroupId=io.hawt.online.examples \ -DartifactId=hawtio-online-example \ -Dversion=1.0.0 \ -DinteractiveMode=false \ -Dpackage=io.hawtio Change into the new project named artifactId (in the above example: hawtio-online-example ) An example hello world application is created, and you can compile it. At this point, the application should be executable locally. Use the mvn spring-boot:run maven goal to test the application: USD mvn spring-boot:run 7.2. Adding Jolokia Starter dependency to the application In order to allow HawtIO to monitor the Camel route in the application, you must add the camel-jolokia-starter dependency. It contains all the necessary transitive dependencies. Add the needed dependencies to the <dependencies> section: <dependencies> ... <!-- Camel --> ... <!-- Dependency is mandatory for exposing Jolokia endpoint --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-jolokia-starter</artifactId> </dependency> <!-- Optional: enables debugging support for Camel --> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-debug</artifactId> <version>4.8.0</version> </dependency> ... </dependencies> For configuration details, see the Jolokia component documentation To enable inflight monitoring also add the following property to the application.properties file according to the Spring Boot documentation : camel.springboot.inflight-repository-browse-enabled=true 7.3. Configuring the application for Deployment to OpenShift The starter already manages the configuration for the Kubernetes/OpenShift environment, so no specific extra configuration is needed. The only mandatory configuration is the name of the port exposed by the POD, it must be named jolokia . spec: containers: - name: my-container ports: - name: jolokia containerPort: 8778 protocol: TCP ........ ....... 7.4. Deploying the Spring Boot application to OpenShift Prerequisites The appropriate project selected (see Documentation ); All files have been configured. Run the following maven command: mvn clean install -DskipTests -P openshift The application is compiled with S2I and deployed to OpenShift. Verify that the Spring Boot application is running correctly: Follow the Verification steps detailed in the Deploying Red Hat build of Quarkus Java applications to OpenShift Container Platform section of the Red Hat build of Quarkus documentation. When your new Spring Boot application is running correctly, it is discovered by the HawtIO instance (depending on its mode - 'Namespace' mode requires it to be in the same project). The new container should be displayed like in the following screenshot: Click Connect to examine the Spring Boot application can be with HawtIO: 7.5. Additional resources Deploying Red Hat build of Quarkus Java applications to OpenShift Container Platform Camel Spring Boot Starter Configuration Deploying a Spring Boot Camel application to OpenShift A Spring Boot application: Getting started Using the JKube OpenShift plugin

Commands:
camel.routecontroller.enabled = true
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-spring-boot -DarchetypeVersion=4.8.0.redhat-00022 -DgroupId=io.hawt.online.examples -DartifactId=hawtio-online-example -Dversion=1.0.0 -DinteractiveMode=false -Dpackage=io.hawtio
mvn spring-boot:run
<dependencies> <!-- Camel --> <!-- Dependency is mandatory for exposing Jolokia endpoint --> <dependency> <groupId>org.apache.camel.springboot</groupId> <artifactId>camel-jolokia-starter</artifactId> </dependency> <!-- Optional: enables debugging support for Camel --> <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-debug</artifactId> <version>4.8.0</version> </dependency> </dependencies>
camel.springboot.inflight-repository-browse-enabled=true
spec: containers: - name: my-container ports: - name: jolokia containerPort: 8778 protocol: TCP ..... ....
mvn clean install -DskipTests -P openshift