Merge pull request #16226 from Michaelin007/master

https://jira.baeldung.com/browse/BAEL-7667
This commit is contained in:
Maiklins 2024-04-02 21:33:41 +02:00 committed by GitHub
commit 4845af6048
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 97 additions and 2 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

@ -35,11 +35,16 @@
<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>
<javax.validation.validation-api.version>2.0.1.Final</javax.validation.validation-api.version>
<camel.version>4.3.0</camel.version>
<camel.version>4.4.1</camel.version>
</properties>
</project>

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 FileCopierCamelRoute());
main.run(args);
}
}

View File

@ -0,0 +1,25 @@
package com.baeldung.apachecamellogging;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileCopierCamelRoute extends RouteBuilder {
private static final 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(process -> {
LOGGER.info("We are passing the message to a FileProcesor bean to capitalize the message body");
})
.bean(FileProcessor.class)
.to("file:data/outbox")
.to("log:com.baeldung.apachecamellogging?showBodyType=false&maxChars=20")
.log(LoggingLevel.DEBUG, "Output Process", "The Process ${id}")
.log("Successfully transfer file: ${file:name}");
}
}

View File

@ -0,0 +1,22 @@
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;