This commit is contained in:
parent
9e46a49f20
commit
a411fd0561
|
@ -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}
|
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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}");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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 org.apache.camel.RoutesBuilder;
|
Loading…
Reference in New Issue