Camel 包含一个开箱即用的日志组件,它对调试很有用,可以轻松跟踪流经路由的消息的内容。 通常,此组件仅在开发路线时临时使用,预计将在生产中删除。
让我们看一个如何使用它来记录 Timer 操作的示例:
package com.sample;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;
public class Logger {
public static void main(String[] args) throws Exception {
Main main = new Main();
main.enableHangupSupport();
main.addRouteBuilder(new RouteLogger());
main.run(args);
}
}
class RouteLogger extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer://simpleTimer?period=1000")
.setBody(simple("Hello from timer at ${header.firedTime}"))
.to("log:myLog");
}
}
结果输出将是:
[hread #0 - timer://simpleTimer] myLog INFO Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello from timer at Wed Aug 19 15:43:31 CEST 2015] [hread #0 - timer://simpleTimer] myLog INFO Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello from timer at Wed Aug 19 15:43:32 CEST 2015] [hread #0 - timer://simpleTimer] myLog INFO Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello from timer at Wed Aug 19 15:43:33 CEST 2015] . . . . . . [hread #0 - timer://simpleTimer] myLog INFO Exchange[ExchangePattern: InOnly, BodyType: String, Body: Hello from timer at Wed Aug 19 15:44:02 CEST 2015]
请注意,默认情况下,日志组件将以 INFO 日志级别记录,
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : http://www.masterspringboot.com/various/camel/using-camel-log-component
内容来源于网络,如有侵权,请联系作者删除!