michaelin007 2024-03-25 12:28:05 +00:00
parent 9e46a49f20
commit a411fd0561
10 changed files with 99 additions and 3 deletions

View File

@ -0,0 +1 @@
Welcome to Baeldung

View File

@ -0,0 +1,4 @@
{
"name" : "phillip",
"age" : 5
}

View File

@ -0,0 +1 @@
WELCOME TO BAELDUNG

View File

@ -0,0 +1 @@
{"name":"phillip","age":5,"transformedName":"PHILLIP","transformedAge":15}

View File

@ -24,19 +24,22 @@
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-junit5</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-main</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>
</dependencies>
<properties>

View File

@ -0,0 +1,13 @@
package com.baeldung.apachecamellogging;
import org.apache.camel.main.Main;
public class CamelLoggingMainApp {
public static void main(String[] args) throws Exception {
Main main = new Main();
main.configure()
.addRoutesBuilder(new FileCopierTracerCamelRoute());
main.run(args);
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.apachecamellogging;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileCopierCamelRoute extends RouteBuilder {
private static Logger logger = LoggerFactory.getLogger(FileCopierCamelRoute.class);
public void configure() {
from("file:data/inbox?noop=true").log("We got an incoming file ${file:name} containing: ${body}")
.to("log:com.baeldung.apachecamellogging?level=INFO")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
logger.info("We are passing the message to a FileProcesor to Capitalize the message body");
}
})
.bean(FileProcessor.class)
.to("file:data/outbox")
.log("Successlly transfer file: ${file:name}");
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.apachecamellogging;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileCopierTracerCamelRoute extends RouteBuilder {
Logger logger = LoggerFactory.getLogger(FileCopierTracerCamelRoute.class);
public void configure() {
getContext().setTracing(true);
from("file:data/json?noop=true").to("log:input?level=INFO")
.unmarshal()
.json(JsonLibrary.Jackson)
.bean(FileProcessor.class, "transform")
.marshal()
.json(JsonLibrary.Jackson)
.to("file:data/output");
;
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.apachecamellogging;
import org.apache.camel.Body;
import java.util.Map;
public class FileProcessor {
public String process(@Body String fileContent) {
String processedContent = fileContent.toUpperCase();
return processedContent;
}
public Map<String, Object> transform(Map<String, Object> input) {
String name = (String) input.get("name");
int age = (int) input.get("age");
input.put("transformedName", name.toUpperCase());
input.put("transformedAge", age + 10);
return input;
}
}

View File

@ -1,4 +1,4 @@
package dynamicrouter;
package com.baeldung.dynamicrouter;
import com.baeldung.dynamicrouter.DynamicRouterRoute;
import org.apache.camel.RoutesBuilder;