This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-examples.git
The following commit(s) were added to refs/heads/master by this push: new fb08204 CAMEL-16056: flight recorder example fb08204 is described below commit fb08204b572494d9b7a20f578e17e621d66c608c Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Jan 20 11:30:41 2021 +0100 CAMEL-16056: flight recorder example --- examples/README.adoc | 4 +- examples/camel-example-flight-recorder/pom.xml | 110 +++++++++++++++++++++ examples/camel-example-flight-recorder/readme.adoc | 44 +++++++++ .../src/main/data/foo.properties | 18 ++++ .../org/apache/camel/example/MyApplication.java | 41 ++++++++ .../main/java/org/apache/camel/example/MyBean.java | 40 ++++++++ .../org/apache/camel/example/MyRouteBuilder.java | 34 +++++++ .../src/main/resources/application.properties | 40 ++++++++ .../src/main/resources/logback.xml | 30 ++++++ examples/pom.xml | 1 + 10 files changed, 361 insertions(+), 1 deletion(-) diff --git a/examples/README.adoc b/examples/README.adoc index 0865844..8c15fae 100644 --- a/examples/README.adoc +++ b/examples/README.adoc @@ -11,7 +11,7 @@ View the individual example READMEs for details. == Examples // examples: START -Number of Examples: 85 (0 deprecated) +Number of Examples: 86 (0 deprecated) [width="100%",cols="4,2,4",options="header"] |=== @@ -141,6 +141,8 @@ Number of Examples: 85 (0 deprecated) | link:camel-example-cdi-metrics/README.adoc[CDI Metrics] (camel-example-cdi-metrics) | Management and Monitoring | Dropwizard Metrics CDI example +| link:camel-example-flight-recorder/readme.adoc[Flight Recorder] (camel-example-flight-recorder) | Management and Monitoring | Diagnosing Camel with Java Flight Recorder + | link:camel-example-jmx/README.adoc[JMX] (camel-example-jmx) | Management and Monitoring | An example showing how to work with Camel and JMX | link:camel-example-management/README.adoc[Management] (camel-example-management) | Management and Monitoring | An example for showing Camel JMX management diff --git a/examples/camel-example-flight-recorder/pom.xml b/examples/camel-example-flight-recorder/pom.xml new file mode 100644 index 0000000..f682211 --- /dev/null +++ b/examples/camel-example-flight-recorder/pom.xml @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<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"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.example</groupId> + <artifactId>examples</artifactId> + <version>3.8.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-flight-recorder</artifactId> + <packaging>jar</packaging> + <name>Camel :: Example :: Java Flight Recorder</name> + <description>Diagnosing Camel with Java Flight Recorder</description> + + <properties> + <category>Management and Monitoring</category> + </properties> + + <dependencyManagement> + <dependencies> + <!-- Add Camel BOM --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bom</artifactId> + <version>${camel.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-main</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bean</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-log</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-timer</artifactId> + </dependency> + + <!-- java flight recorder --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jfr</artifactId> + </dependency> + + <!-- logging --> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-core</artifactId> + <version>${logback-version}</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback-version}</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <!-- to run the application --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-maven-plugin</artifactId> + <version>${camel.version}</version> + <configuration> + <mainClass>org.apache.camel.example.MyApplication</mainClass> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/examples/camel-example-flight-recorder/readme.adoc b/examples/camel-example-flight-recorder/readme.adoc new file mode 100644 index 0000000..04669da --- /dev/null +++ b/examples/camel-example-flight-recorder/readme.adoc @@ -0,0 +1,44 @@ +== Camel Example Flight Recorder + +This example demonstrates how to integrate Camel with Java Flight Recorder +which can be used to diagnose your JVM applications. + +In JDK Mission Control (visual tool for flight recorder), you can browse Camel events +which for example can help diagnose problems with slow startup of Camel routes. + +=== How to run + +You can run this example using + + mvn camel:run + +And then after Camel has been started up, a recording is saved to disk, where you can see +from the logs the location of the file, such as: + + Flight recorder recording saved: /Users/davsclaus/camel-recording13093057117733087947.jfr + +You can then open this `jfr` file in JDK Mission Control and browse the information. +In the Event Browser you can find the Camel Startup events, which can help pin-point to where +Camel is slow to startup. + +NOTE: The recording is started when Camel is bootstrapped, and therefore not from the very beginning of the JVM. +To capture from the JVM beginning you can run java with `-XX:StartFlightRecording`. + +=== Using logger instead of flight recorder + +Instead of capturing a recording you can configure Camel to log the startup steps instead by setting + + camel.main.startup-recorder = logging + +In the `application.properties` file. + + +=== Help and contributions + +If you hit any problem using Camel or have some feedback, then please +https://camel.apache.org/support.html[let us know]. + +We also love contributors, so +https://camel.apache.org/contributing.html[get involved] :-) + +The Camel riders! diff --git a/examples/camel-example-flight-recorder/src/main/data/foo.properties b/examples/camel-example-flight-recorder/src/main/data/foo.properties new file mode 100644 index 0000000..b43e6bc --- /dev/null +++ b/examples/camel-example-flight-recorder/src/main/data/foo.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +bye = Bye \ No newline at end of file diff --git a/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyApplication.java b/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyApplication.java new file mode 100644 index 0000000..34decfb --- /dev/null +++ b/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyApplication.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.example; + +import org.apache.camel.main.Main; + +/** + * Main class that boot the Camel application + */ +public final class MyApplication { + + private MyApplication() { + } + + public static void main(String[] args) throws Exception { +// System.out.println(">>>>>>>>>>>>>>> sleep 10 "); +// Thread.sleep(10000); + + // use Camels Main class + Main main = new Main(); + // and add the routes (you can specify multiple classes) + main.configure().addRoutesBuilder(MyRouteBuilder.class); + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) + main.run(args); + } + +} diff --git a/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyBean.java b/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyBean.java new file mode 100644 index 0000000..a47ca1e --- /dev/null +++ b/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyBean.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.example; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MyBean { + + private static final Logger LOG = LoggerFactory.getLogger(MyBean.class); + + public MyBean() { + // force slow startup + try { + LOG.warn("Forcing 2 sec delay to have slow startup"); + Thread.sleep(2000); + } catch (Exception e) { + // ignore + } + } + + public String hello() { + return "Hello how are you?"; + } + +} diff --git a/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyRouteBuilder.java b/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyRouteBuilder.java new file mode 100644 index 0000000..2470784 --- /dev/null +++ b/examples/camel-example-flight-recorder/src/main/java/org/apache/camel/example/MyRouteBuilder.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.example; + +import org.apache.camel.builder.RouteBuilder; + +public class MyRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + from("timer:foo?period={{myPeriod}}") + .to("log:fast?level=OFF") + .to("direct:slow") + .log("${body}"); + + from("direct:slow") + .to("log:slow?level=OFF") + .bean(MyBean.class, "hello"); + } +} diff --git a/examples/camel-example-flight-recorder/src/main/resources/application.properties b/examples/camel-example-flight-recorder/src/main/resources/application.properties new file mode 100644 index 0000000..d2c6005 --- /dev/null +++ b/examples/camel-example-flight-recorder/src/main/resources/application.properties @@ -0,0 +1,40 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# to configure camel main +# here you can configure options on camel main (see MainConfigurationProperties class) +camel.main.name = MySlowCamel + +# enable startup recorder which can be logging or java-flight-recorder +# will autodetect camel-jfr from classpath and enable java-flight-recorder +# however this can be turned off by setting the option to false, or change to logging +#camel.main.startup-recorder = false +#camel.main.startup-recorder = logging + +# automatic start a JFR recording and dump it to disk after Camel is started +camel.main.startup-recorder-recording = true +# what JFR profile to use (default or profile) the profile controls what and how much data to capture and record +#camel.main.startup-recorder-profile = profile +# to keep recording for 60 seconds and will be auto-saved on timeout +# by default the recording is saved when Camel has been started (short lived) +#camel.main.startup-recorder-duration = 60 + +# run in lightweight mode to be tiny as possible +camel.main.lightweight = true + +# properties used in the route +myPeriod = 1000 diff --git a/examples/camel-example-flight-recorder/src/main/resources/logback.xml b/examples/camel-example-flight-recorder/src/main/resources/logback.xml new file mode 100644 index 0000000..a798d0b --- /dev/null +++ b/examples/camel-example-flight-recorder/src/main/resources/logback.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<configuration> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + + <root level="INFO"> + <appender-ref ref="STDOUT" /> + </root> +</configuration> diff --git a/examples/pom.xml b/examples/pom.xml index 2d12f43..d3cff30 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -96,6 +96,7 @@ <module>camel-example-cdi-aws-s3</module> <module>camel-example-cdi-cassandraql</module> <module>camel-example-fhir</module> + <module>camel-example-flight-recorder</module> <module>camel-example-cdi-kubernetes</module> <module>camel-example-cdi-metrics</module> <module>camel-example-cdi-minio</module>