This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-examples.git
commit 4c98a59945eaba1b62cf379fa2b0c6446cb20681 Author: Claus Ibsen <[email protected]> AuthorDate: Fri Nov 17 09:15:50 2023 +0100 Example for main with micrometer --- main-micrometer/README.adoc | 59 +++++++++ main-micrometer/pom.xml | 144 +++++++++++++++++++++ .../org/apache/camel/example/MyApplication.java | 36 ++++++ .../src/main/resources/application.properties | 39 ++++++ .../src/main/resources/camel/demo.camel.yaml | 40 ++++++ .../src/main/resources/log4j2.properties | 23 ++++ pom.xml | 1 + 7 files changed, 342 insertions(+) diff --git a/main-micrometer/README.adoc b/main-micrometer/README.adoc new file mode 100644 index 00000000..6c632ee2 --- /dev/null +++ b/main-micrometer/README.adoc @@ -0,0 +1,59 @@ +== Camel Example Main Micrometer + +This example shows how to run Camel standalone with Micrometer metrics +and with HTTP endpoint for exposing statistics for scraping by Prometheus. + +The application is configured in the `application.properties` file. + +=== Build + +First compile the example by executing: + +[source,sh] +---- +$ mvn compile +---- + +=== How to run + +Then you can run this example using + +[source,sh] +---- +$ mvn camel:run +---- + +=== Micrometer + +The statistics from Micrometer can be observed from HTTP at: + + http://localhost:8080/q/metrics + +=== Camel CLI + +This application is integrated with the Camel CLI via the `camel-cli-connector` dependency (see `pom.xml`). +This allows to use the Camel CLI to manage this application, such as: + + $mvn package camel:run + +And then use the CLI to see status: + + $camel get + PID NAME CAMEL PLATFORM READY STATUS AGE TOTAL FAILED INFLIGHT SINCE-LAST + 90491 org.apache.camel.example.My… 3.19.0-SNAPSHOT Camel 1/1 Running 20s 11 0 0 0s + + +=== Camel Web Console + +This example comes with embedded developer console that is accessible via `http://localhost:8080/q/dev`. +You can also check status of health-check via `http://localhost:8080/q/health`. + +=== Help and contributions + +If you hit any problem using Camel or have some feedback, then please +https://camel.apache.org/community/support/[let us know]. + +We also love contributors, so +https://camel.apache.org/community/contributing/[get involved] :-) + +The Camel riders! diff --git a/main-micrometer/pom.xml b/main-micrometer/pom.xml new file mode 100644 index 00000000..ac8313b0 --- /dev/null +++ b/main-micrometer/pom.xml @@ -0,0 +1,144 @@ +<?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>camel-examples</artifactId> + <version>4.2.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-example-main-micrometer</artifactId> + <packaging>jar</packaging> + <name>Camel :: Example :: Main Micrometer</name> + <description>Standalone Camel with Micrometer and Prometheus</description> + + <properties> + <category>Observability</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-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-main</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-timer</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-micrometer-prometheus</artifactId> + </dependency> + + <!-- camel-main web console --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-platform-http-main</artifactId> + </dependency> + <!-- developer consoles for web console --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-console</artifactId> + </dependency> + <!-- JMX metrics for web console --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-management</artifactId> + </dependency> + + <!-- camel-cli --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-cli-connector</artifactId> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <version>${log4j2-version}</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j2-impl</artifactId> + <version>${log4j2-version}</version> + <scope>runtime</scope> + </dependency> + <!-- for testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-main-junit5</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-maven-plugin</artifactId> + <version>${camel.version}</version> + <configuration> + <logClasspath>false</logClasspath> + <mainClass>org.apache.camel.example.MyApplication</mainClass> + </configuration> + </plugin> + </plugins> + </build> + <profiles> + <profile> + <id>camel.debug</id> + <activation> + <property> + <name>camel.debug</name> + <value>true</value> + </property> + </activation> + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-debug</artifactId> + </dependency> + </dependencies> + </profile> + </profiles> +</project> diff --git a/main-micrometer/src/main/java/org/apache/camel/example/MyApplication.java b/main-micrometer/src/main/java/org/apache/camel/example/MyApplication.java new file mode 100644 index 00000000..31197dc0 --- /dev/null +++ b/main-micrometer/src/main/java/org/apache/camel/example/MyApplication.java @@ -0,0 +1,36 @@ +/* + * 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 { + // use Camels Main class + Main main = new Main(MyApplication.class); + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) + main.run(args); + } + +} diff --git a/main-micrometer/src/main/resources/application.properties b/main-micrometer/src/main/resources/application.properties new file mode 100644 index 00000000..1364adcd --- /dev/null +++ b/main-micrometer/src/main/resources/application.properties @@ -0,0 +1,39 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# here you can configure options on camel main +# https://camel.apache.org/components/next/others/main.html +camel.main.name = MyCoolCamel + +# allows source:line precise logging +camel.main.sourceLocationEnabled=true + +# enable http server +camel.server.enabled = true +camel.server.dev-console-enabled = true +camel.server.health-check-enabled = true +# turn on micrometer prometheus on q/metrics +camel.server.metrics-enabled = true + +# micrometer configurations +camel.metrics.enabled=true +camel.metrics.enable-message-history=true +# additional binders to include cpu, jvm info etc +camel.metrics.binders=processor,jvm-info,file-descriptor + +# application properties +hi = Hello diff --git a/main-micrometer/src/main/resources/camel/demo.camel.yaml b/main-micrometer/src/main/resources/camel/demo.camel.yaml new file mode 100644 index 00000000..74101b15 --- /dev/null +++ b/main-micrometer/src/main/resources/camel/demo.camel.yaml @@ -0,0 +1,40 @@ +- route: + nodePrefixId: route-e2a + id: route-8847 + from: + uri: timer + id: from-0922 + parameters: + timerName: timer1 + delay: '1000' + period: '5000' + steps: + - setBody: + expression: + simple: + expression: Hello World + id: simple-3fc3 + id: setBody-b8e4 + - to: + uri: direct + id: to-280f + parameters: + name: direct1 +- route: + nodePrefixId: route-6ce + id: route-a9b6 + from: + uri: direct + id: from-a1fa + parameters: + name: direct1 + steps: + - setBody: + constant: 'HELLO' + id: log-dcfc +- rest: + id: rest-8cd4 + post: + - path: /rest-api + to: direct:direct1 + id: post-032f diff --git a/main-micrometer/src/main/resources/log4j2.properties b/main-micrometer/src/main/resources/log4j2.properties new file mode 100644 index 00000000..d9f0508a --- /dev/null +++ b/main-micrometer/src/main/resources/log4j2.properties @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = [%30.30t] %-30.30c{1} %-5p %m%n +rootLogger.level = INFO +rootLogger.appenderRef.out.ref = out diff --git a/pom.xml b/pom.xml index 62c6e0a2..357f6497 100644 --- a/pom.xml +++ b/pom.xml @@ -116,6 +116,7 @@ <module>main-health</module> <module>main-joor</module> <module>main-lambda</module> + <module>main-micrometer</module> <module>main-tiny</module> <module>main-xml</module> <module>main-yaml</module>
