michaelin007 2024-03-26 12:28:14 +00:00
parent a411fd0561
commit 2e2ac76b45
4 changed files with 9 additions and 11 deletions

View File

@ -44,7 +44,7 @@
<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>

View File

@ -7,7 +7,7 @@ public class CamelLoggingMainApp {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Main main = new Main(); Main main = new Main();
main.configure() main.configure()
.addRoutesBuilder(new FileCopierTracerCamelRoute()); .addRoutesBuilder(new FileCopierCamelRoute());
main.run(args); main.run(args);
} }
} }

View File

@ -1,7 +1,6 @@
package com.baeldung.apachecamellogging; package com.baeldung.apachecamellogging;
import org.apache.camel.Exchange; import org.apache.camel.LoggingLevel;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder; import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -9,19 +8,19 @@ import org.slf4j.LoggerFactory;
public class FileCopierCamelRoute extends RouteBuilder { public class FileCopierCamelRoute extends RouteBuilder {
private static Logger logger = LoggerFactory.getLogger(FileCopierCamelRoute.class); private static final Logger LOGGER = LoggerFactory.getLogger(FileCopierCamelRoute.class);
public void configure() { public void configure() {
from("file:data/inbox?noop=true").log("We got an incoming file ${file:name} containing: ${body}") from("file:data/inbox?noop=true").log("We got an incoming file ${file:name} containing: ${body}")
.to("log:com.baeldung.apachecamellogging?level=INFO") .to("log:com.baeldung.apachecamellogging?level=INFO")
.process(new Processor() {
@Override .process(process -> {
public void process(Exchange exchange) throws Exception { LOGGER.info("We are passing the message to a FileProcesor bean to capitalize the message body");
logger.info("We are passing the message to a FileProcesor to Capitalize the message body");
}
}) })
.bean(FileProcessor.class) .bean(FileProcessor.class)
.to("file:data/outbox") .to("file:data/outbox")
.to("log:com.baeldung.apachecamellogging?showBodyType=false&maxChars=20")
.log(LoggingLevel.DEBUG, "Output Process", "The Process ${id}")
.log("Successlly transfer file: ${file:name}"); .log("Successlly transfer file: ${file:name}");
} }
} }

View File

@ -18,6 +18,5 @@ public class FileCopierTracerCamelRoute extends RouteBuilder {
.marshal() .marshal()
.json(JsonLibrary.Jackson) .json(JsonLibrary.Jackson)
.to("file:data/output"); .to("file:data/output");
;
} }
} }