How to Camel Debug a Camel Quarkus route deployed on OpenShift from VS Code
This how-to will not cover in details the following points, it is assumed that it is installed/preconfigured:
Note that this tutorial was made with the following versions:
Ctrl+Shift+P)Camel: Create a Camel Route using Java DSLMyRouteCtrl+Shift+P)Camel: Create a Camel Quarkus projectYou can notice the Camel route in src/main/java/com/acme/myproject folder (to adapt if parameters were customized)
camel.debug profile, you need to add a Jolokia enablement configuration:<profile> <id>camel.debug</id> <activation> <property> <name>camel.debug</name> <value>true</value> </property> </activation> <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-debug</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.7.1</version> <executions> <execution> <id>copy</id> <phase>generate-sources</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>org.jolokia</groupId> <artifactId>jolokia-agent-jvm</artifactId> <version>2.0.3</version> <type>jar</type> <classifier>javaagent</classifier> </artifactItem> </artifactItems> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin> <plugin> <groupId>${quarkus.platform.group-id}</groupId> <artifactId>quarkus-maven-plugin</artifactId> <configuration> <jvmArgs>-Dcamel.main.shutdownTimeout=30 -Dquarkus.camel.source-location-enabled=true -javaagent:target/dependency/jolokia-agent-jvm-javaagent.jar=port=7878,host=localhost</jvmArgs> </configuration> </plugin> </plugins> </build> </profile>
In a nutshell, the Jolokia jvm agent jar is copied in target folder. Then when quarkus-dev is used, the javaagent is configured to point to this downloaded jar.
Application explorer view in the primary sidebar should list it.Components view of the primary sidebar, click on Create component Create button in panel From Existing Local Codebase my-camel-routeNext Create component devfile.yaml filecamel.debug profile and expose Jolokia port, it will give something like:commands: - exec: commandLine: ./mvnw -Dmaven.repo.local=/home/user/.m2/repository compile component: tools workingDir: ${PROJECT_SOURCE} id: init-compile - exec: commandLine: ./mvnw -Dmaven.repo.local=/home/user/.m2/repository quarkus:dev -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager component: tools group: isDefault: true kind: run hotReloadCapable: true workingDir: ${PROJECT_SOURCE} id: dev-run - exec: commandLine: ./mvnw -Dmaven.repo.local=/home/user/.m2/repository quarkus:dev -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Ddebug=${DEBUG_PORT} -Pcamel.debug component: tools group: isDefault: true kind: debug hotReloadCapable: true workingDir: ${PROJECT_SOURCE} id: dev-debug components: - container: args: - tail - -f - /dev/null endpoints: - name: port-8080-tcp protocol: tcp targetPort: 8080 - name: port-jolokia protocol: http targetPort: 7878 env: - name: DEBUG_PORT value: "5858" image: registry.access.redhat.com/ubi8/openjdk-21:1.19-1 memoryLimit: 1024Mi mountSources: true volumeMounts: - name: m2 path: /home/user/.m2 name: tools - name: m2 volume: size: 3Gi events: postStart: - init-compile metadata: description: Java application using Quarkus and OpenJDK 21 displayName: Quarkus Java icon: https://design.jboss.org/quarkus/logo/final/SVG/quarkus_icon_rgb_default.svg language: Java name: camel-quarkus-demo projectType: Quarkus tags: - Java - Quarkus version: 1.5.0 website: https://quarkus.io schemaVersion: 2.2.0 starterProjects: - name: community zip: location: https://code.quarkus.io/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-micrometer&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift&cn=devfile&j=21 - name: redhat-product zip: location: https://code.quarkus.redhat.com/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift&j=21
Start dev__ / \__ Developing using the "camel-quarkus-demo" Devfile \__/ \ Namespace: apupier-dev / \__/ odo version: v3.16.1 (817faa69f-nightly) \__/ ↪ Running on the cluster in Dev mode ✓ Web console accessible at http://localhost:20000/ ✓ API Server started at http://localhost:20000/api/v1 ✓ API documentation accessible at http://localhost:20000/swagger-ui/ • Waiting for Kubernetes resources ... ✓ Added storage m2 to component =================== ⚠Pod is Pending =================== ✓ Pod is Running ✓ Syncing files into the container [2s] ✓ Executing post-start command in container (command: init-compile) [27s] • Executing the application (command: dev-debug) ... ✓ Waiting for the application to be ready [36s] - Forwarding from 127.0.0.1:20001 -> 8080 - Forwarding from 127.0.0.1:20002 -> 7878
Follow log This kind of log will appear when the route is started:tools: 2024-08-06 12:44:16,282 INFO [MyRoute:12] (Camel (camel-1) thread #2 - timer://java) Hello Camel from route1
odo dev log of the started component, the mapped port for Jolokia is visible. it corresponds to the 7878. In our case, it is 20002..vscode/launch.json{ "name": "Jolokia attach", "type": "apache.camel", "request": "attach", "attach_jmx_url": "service:jmx:jolokia://localhost:20002/jolokia/" }
Run and Debug Activity (Ctrl+Shift+D)Jolokia attach in the drop-downRun buttonCamel debugger is operational. You can place breakpoints, inspect ad modify variables, go step by step and more.
For instance, open src/main/java/com/acme/myproject/MyRoute.java and place a breakpoint on the log line.
Enjoy!
Some ideas of related improvements:
quarkus:dev is activated apache/camel-quarkus#3876Please provide feedback and ideas with your preferred channel: