Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>camel-observability</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>camel-observability-spring</artifactId>

<properties>
<java.version>17</java.version>
</properties>

<dependencyManagement>
<dependencies>
<!-- Camel BOM -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.11</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>4.18.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-observation-starter</artifactId>
<version>4.18.0</version>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>1.15.9</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.5.32</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.32</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<person user="james">
<firstName>James</firstName>
<lastName>Strachan</lastName>
<city>London</city>
</person>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<person user="hiram">
<firstName>Hiram</firstName>
<lastName>Chirino</lastName>
<city>Tampa</city>
</person>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.baeldung.camel.observability;

import org.apache.camel.observation.starter.CamelObservation;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;


@CamelObservation
@SpringBootApplication
public class FirstCamelSpringBootApplication {

public static void main(String[] args) {
SpringApplication.run(FirstCamelSpringBootApplication.class, args);
}

@Bean
SimpleProcessor simpleProcessor() {
return new SimpleProcessor();
}

@Bean
SimpleRouteBuilder simpleRouteBuilder(SimpleProcessor simpleProcessor) {
return new SimpleRouteBuilder(simpleProcessor);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.baeldung.camel.observability;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;

public class SimpleProcessor implements Processor {

private static final DocumentBuilderFactory factory = DocumentBuilderFactory.newDefaultInstance();

@Override
public void process(Exchange exchange) throws Exception {
String body = exchange.getMessage().getBody(String.class);
String processedAt = LocalDateTime.now().toString();
InputStream stream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
Document document = factory.newDocumentBuilder().parse(stream);
Element root = document.getDocumentElement();
Element newElemeent = document.createElement("processed");
newElemeent.setTextContent(processedAt);
root.appendChild(newElemeent);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter stringWriter = new StringWriter();
transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
String newBody = stringWriter.toString();
exchange.getMessage().setBody(newBody);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.baeldung.camel.observability;

import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;

public class SimpleRouteBuilder extends RouteBuilder {

private final SimpleProcessor simpleProcessor;

@Autowired
public SimpleRouteBuilder(SimpleProcessor simpleProcessor) {
this.simpleProcessor = simpleProcessor;
}

public void configure() {
from("file://src/data?noop=true")
.process(simpleProcessor)
.choice()
.when(xpath("/person/city = 'London'"))
.log("UK message")
.to("file:target/messages/uk")
.log("UK message 2")
.to("file:target/messages/general-sink")
.otherwise()
.log("Other message")
.to("file:target/messages/others")
.log("Other message 2")
.to("file:target/messages/general-sink");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
spring:
application:
name: first-camel-spring-boot
camel:
main:
run-controller: true
opentelemetry2:
enabled: true
trace-processors: true
trace-headers-inclusion: true
management:
tracing:
sampling:
probability: 1.0
endpoints:
web:
exposure:
include: health,metrics,prometheus
server:
port: 7654
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>camel-observability</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>camel-observability-standalone</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencyManagement>
<dependencies>
<!-- Camel BOM -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bom</artifactId>
<version>4.17.0</version>
<scope>import</scope>
<type>pom</type>
</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-observability-services</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-opentelemetry2</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.29</version>
<scope>compile</scope>
</dependency>

<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<version>3.22.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<defaultGoal>install</defaultGoal>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

<!-- Allows the example to be run via 'mvn camel:run' -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>3.18.4</version>
<configuration>
<logClasspath>true</logClasspath>
<mainClass>com.baeldung.camel.observability.MainApp</mainClass>
</configuration>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<person user="james">
<firstName>James</firstName>
<lastName>Strachan</lastName>
<city>London</city>
</person>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<person user="hiram">
<firstName>Hiram</firstName>
<lastName>Chirino</lastName>
<city>Tampa</city>
</person>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.baeldung.camel.observability;

import org.apache.camel.main.Main;

public class MainApp {

public static void main(String... args) throws Exception {
Main main = new Main();
main.configure().addRoutesBuilder(new SimpleRouteBuilder());
main.bind("SimpleProcessor", new SimpleProcessor());
main.run(args);
}

}

Loading