Merge pull request #16226 from Michaelin007/master
https://jira.baeldung.com/browse/BAEL-7667
This commit is contained in:
commit
4845af6048
|
@ -0,0 +1 @@
|
||||||
|
Welcome to Baeldung
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"name" : "phillip",
|
||||||
|
"age" : 5
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
WELCOME TO BAELDUNG
|
|
@ -0,0 +1 @@
|
||||||
|
{"name":"phillip","age":5,"transformedName":"PHILLIP","transformedAge":15}
|
|
@ -35,11 +35,16 @@
|
||||||
<artifactId>camel-main</artifactId>
|
<artifactId>camel-main</artifactId>
|
||||||
<version>${camel.version}</version>
|
<version>${camel.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.camel</groupId>
|
||||||
|
<artifactId>camel-jackson</artifactId>
|
||||||
|
<version>${camel.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<javax.validation.validation-api.version>2.0.1.Final</javax.validation.validation-api.version>
|
<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>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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}");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package dynamicrouter;
|
package com.baeldung.dynamicrouter;
|
||||||
|
|
||||||
import com.baeldung.dynamicrouter.DynamicRouterRoute;
|
import com.baeldung.dynamicrouter.DynamicRouterRoute;
|
||||||
import org.apache.camel.RoutesBuilder;
|
import org.apache.camel.RoutesBuilder;
|
Loading…
Reference in New Issue