Skip to content

Commit 4e4870a

Browse files
committed
CAMEL-21348: Adds jolokia example
1 parent 3a209fd commit 4e4870a

File tree

12 files changed

+549
-1
lines changed

12 files changed

+549
-1
lines changed

README.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ readme's instructions.
2727
=== Examples
2828

2929
// examples: START
30-
Number of Examples: 60 (0 deprecated)
30+
Number of Examples: 61 (0 deprecated)
3131

3232
[width="100%",cols="4,2,4",options="header"]
3333
|===
@@ -109,6 +109,8 @@ Number of Examples: 60 (0 deprecated)
109109

110110
| link:health-checks/readme.adoc[Health Checks] (health-checks) | Management and Monitoring | An example how to use custom health-checks
111111

112+
| link:jolokia/README.adoc[Jolokia] (jolokia) | Management and Monitoring | An example that uses Jolokia to monitor and to manage Camel Routes
113+
112114
| link:metrics/README.adoc[Metrics] (metrics) | Management and Monitoring | An example showing how to work with Camel and Spring Boot and report metrics to Graphite
113115

114116
| link:observation/README.adoc[Micrometer Observation] (observation) | Management and Monitoring | An example showing how to trace incoming and outgoing messages from Camel with Micrometer Observation

jolokia/README.adoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
== Jolokia Example
2+
3+
This example shows how Camel can be monitored and managed using https://jolokia.org[Jolokia] and https://hawt.io[Hawtio]
4+
5+
=== How to run
6+
7+
You can run this example using
8+
9+
mvn spring-boot:run
10+
11+
=== Run Hawtio
12+
13+
Hawtio is a lightweight and modular Web console for managing Java applications.
14+
It can be installed/used in more ways, see https://hawt.io/docs/get-started.html[Get Started Guide]
15+
16+
In the example I am suggesting the jbang way to install it
17+
18+
jbang app install hawtio@hawtio/hawtio
19+
hawtio --port 8090
20+
21+
=== Connect to the application
22+
23+
Open Hawtio UI at http://localhost:8090/hawtio/connect/remote[] and click on `Add connection` button filling the properties as in the picture
24+
25+
- Name: `as you prefer [eg camel]`
26+
- Scheme: `http`
27+
- Host: `localhost`
28+
- Port: `8778`
29+
- Path: `/jolokia/`
30+
31+
image::docs/add-connection.png[]
32+
33+
click on `Add` button, this action will create a connection in the list of the connections,
34+
then connect on it clicking on the button `Connect`
35+
36+
then it is possible to monitor and to manage routes
37+
38+
image::docs/route-monitor.png[]
39+
40+
=== Configure Jolokia endpoint
41+
42+
The Jolokia autoconfiguration is an alternative to the Jolokia agent,
43+
more information about the usage and the configuration can be found on https://github.com/apache/camel-spring-boot/blob/main/components-starter/camel-jolokia-starter/src/main/docs/jolokia.adoc[component guide]
44+
45+
=== Help and contributions
46+
47+
If you hit any problem using Camel or have some feedback, then please
48+
https://camel.apache.org/community/support/[let us know].
49+
50+
We also love contributors, so
51+
https://camel.apache.org/community/contributing/[get involved] :-)
52+
53+
The Camel riders!

jolokia/docs/add-connection.png

44.5 KB
Loading

jolokia/docs/route-monitor.png

63.6 KB
Loading

jolokia/pom.xml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<artifactId>examples</artifactId>
26+
<groupId>org.apache.camel.springboot.example</groupId>
27+
<version>4.9.0-SNAPSHOT</version>
28+
</parent>
29+
30+
<artifactId>camel-example-spring-boot-jolokia</artifactId>
31+
<name>Camel SB Examples :: Jolokia</name>
32+
<description>An example that uses Jolokia to monitor and to manage Camel Routes</description>
33+
<packaging>jar</packaging>
34+
35+
<properties>
36+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
37+
<category>Management and Monitoring</category>
38+
</properties>
39+
40+
<dependencyManagement>
41+
<dependencies>
42+
<!-- Camel BOM -->
43+
<dependency>
44+
<groupId>org.apache.camel.springboot</groupId>
45+
<artifactId>camel-spring-boot-bom</artifactId>
46+
<version>${project.version}</version>
47+
<type>pom</type>
48+
<scope>import</scope>
49+
</dependency>
50+
<!-- Spring Boot BOM -->
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-dependencies</artifactId>
54+
<version>${spring-boot-version}</version>
55+
<type>pom</type>
56+
<scope>import</scope>
57+
</dependency>
58+
</dependencies>
59+
</dependencyManagement>
60+
61+
<dependencies>
62+
63+
<!-- Spring Boot -->
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-web</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-starter-actuator</artifactId>
71+
</dependency>
72+
73+
<!-- Camel -->
74+
<dependency>
75+
<groupId>org.apache.camel.springboot</groupId>
76+
<artifactId>camel-spring-boot-starter</artifactId>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.apache.camel.springboot</groupId>
80+
<artifactId>camel-stream-starter</artifactId>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.apache.camel.springboot</groupId>
84+
<artifactId>camel-jolokia-starter</artifactId>
85+
</dependency>
86+
87+
</dependencies>
88+
89+
<build>
90+
<plugins>
91+
<plugin>
92+
<groupId>org.springframework.boot</groupId>
93+
<artifactId>spring-boot-maven-plugin</artifactId>
94+
<version>${spring-boot-version}</version>
95+
<executions>
96+
<execution>
97+
<goals>
98+
<goal>repackage</goal>
99+
</goals>
100+
</execution>
101+
</executions>
102+
</plugin>
103+
</plugins>
104+
</build>
105+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.example;
18+
19+
import org.springframework.beans.factory.annotation.Value;
20+
import org.springframework.stereotype.Component;
21+
22+
/**
23+
* A bean that returns a message when you call the {@link #saySomething()} method.
24+
* <p/>
25+
* Uses <tt>@Component("myBean")</tt> to register this bean with the name <tt>myBean</tt>
26+
* that we use in the Camel route to lookup this bean.
27+
*/
28+
@Component("myBean")
29+
public class MySpringBean {
30+
31+
@Value("${greeting}")
32+
private String say;
33+
34+
public String saySomething() {
35+
return say;
36+
}
37+
38+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.example;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
@SpringBootApplication
23+
public class MySpringBootApplication {
24+
25+
/**
26+
* A main method to start this application.
27+
*/
28+
public static void main(String[] args) {
29+
SpringApplication.run(MySpringBootApplication.class, args);
30+
}
31+
32+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.example;
18+
19+
import org.apache.camel.builder.RouteBuilder;
20+
import org.springframework.stereotype.Component;
21+
22+
/**
23+
* A simple Camel route that triggers from a timer and calls a bean and prints to system out.
24+
* <p/>
25+
* Use <tt>@Component</tt> to make Camel auto detect this route when starting.
26+
*/
27+
@Component
28+
public class MySpringBootRouter extends RouteBuilder {
29+
30+
@Override
31+
public void configure() {
32+
from("timer:hello?period={{timer.period}}").routeId("hello")
33+
.transform().method("myBean", "saySomething")
34+
.filter(simple("${body} contains 'foo'"))
35+
.to("log:foo")
36+
.end()
37+
.to("stream:out");
38+
}
39+
40+
}

0 commit comments

Comments
 (0)