Apache的骆驼bindy - 如何登录或调试 [英] Apache camel bindy - how to log or debug

查看:268
本文介绍了Apache的骆驼bindy - 如何登录或调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从骆驼bindy一些日志信息。我使用的是BindyCsvDataFormat bindyProduct带有注释的产品豆和csv文件作为源使用了。

I'm trying to get some log informations from camel bindy. I had a working setup using an BindyCsvDataFormat bindyProduct with an annotated product-bean and an csv file as source.

现在我改变了CSV文件和注解的bean。处理接缝处卡住的bindy处理器中,但我没有得到任何信息/日志。我debugProcessor根本没有被达到。如果我把它解组步骤之前,那么它会记录一些东西,我可以调试到它。我不知道为什么新的文件不符合/匹配任何更多的,为什么没有日志或异常或任何会的帮助。

Now I changed the CSV file and the annotated bean. The processing seams to get stuck within the bindy processor, but I do not get any Informations/logs. My debugProcessor is not reached at all. If I put it before the unmarshal step, then it logs some stuff and I can debug into it. I wonder why the new files do not fit / match any more and why there are no logs OR exceptions or whatever would be of an help.

        from("file:csv-testdata")
        .unmarshal(bindyProduct)    
        .process(debugProcessor)

在此先感谢
AJ

Thanks in advance AJ

推荐答案

当我问的问题,我在我的骑骆驼体验最开始。在此期间,我发现了一些伟大的方式来实现的,我一直在寻找。所以,如果有人在寻找一个答案:

Logging of Exceptions in apache camel

When I asked the question, I was at the very beginning of my camel riding experience. In the meantime I found out some great ways to to achieve, what I was looking for. So if someone else is searching for an answer to this question:

1.1添加依存关系登录到你的pom.xml例如

1.1 Add dependencies for logging to your pom.xml e.g

<groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
</dependency>

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.5</version>
</dependency>

1.2添加log4j.properties文件到你的src /主/资源文件夹(如果你想使用log4j的)。定义日志等级,追加程序等有

1.2 Add log4j.properties file to your src/main/resources folder (if you want to use log4j). Define loglevel, appenders etc. there

1.3日志记录添加到您的路线

1.3 add the logging to your route

from("...")
.unmarshal(bindyProduct)
.to("log:com.your.package.YourChosenName?level=ERROR&multiline=true&showCaughtException=true")
.to(...);

所有选项的列表可以在这里找到
http://camel.apache.org/log.html
你可以使用

&showAll=true 

登录类似的报头,属性等身体

to log all Informations like headers, properties, body etc

请记住,的网址记录级的严重级别=选项必须等于或大于一高,你在log4j.properties文件中定义

Keep in mind, that the severity of the loglevel of the URLs "level=" option must be equal or higher than the one, you defined in your log4j.properties file

2.1写DebugProcessor
该处理器具有实施
    公共无效过程(外汇兑换)抛出异常{

2.1 write an DebugProcessor The Processor has to implement public void process(Exchange exchange) throws Exception {

如果你想知道为什么你找不到任何异常

if your wondering why you can't find any Exception in

exchange.getException()

尝试通过检索它

Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);

做什么都你这个异常喜欢(登录到SYSOUT,...)

do what ever you like with this exception (log to sysout, ...)

2.2线调试器到你RouteBuilder的Java类中的路线(或其他地方,春天,XML,...)

2.2 Wire your debugger into your route within your RouteBuilder Java-Class (or elsewhere, Spring, XML, ...)

DebugProcessor debugProcessor1 = new DebugProcessor();

from("...")
.unmarshal(bindyProduct)
.process(debugProcessor1)
.to(...);

3。第三种方法

用骆驼.doTry()/。doCatch()或(甚至更好)使用onException的()航线

http://camel.apache.org/exception-clause.html / camel.apache.org/try-catch-finally.html)

3. Third approach

Use camels .doTry()/.doCatch() or (maybe even better) use an onException() route

(http://camel.apache.org/exception-clause.html / camel.apache.org/try-catch-finally.html)

3.1建立从要调试的路线分开的onException的()航线

3.1 Build an onException() route separated from the route you want to debug

以下onException的路线汇集例外,写下来一个不错的,可读的方式(通过Velocity模板),每5秒或10产生的异常:

The following onException route aggregates exceptions and writes them down a nice, human readable way (via velocity template) , every 5 seconds or 10 exeptions:

onException(Exception.class) // OR a special excepion (io, etc)
        .aggregate(header("CamelFileParent"),
                new ExceptionAggregationStrategy())
                .completionSize(10).completionTimeout(5000)
        .to("velocity:velocity/errors.log.vm")
        .to("file:camel/xml-out?fileName=errors-${file:name.noext}-${date:now:yyyy-MM-dd_HH-mm-ss-SSS}.log");

这只是一个例子,你可以做你想做什么都和骆驼能,例如向他们发送邮件,将它们放在一个数据库等。

This is just an example, you can do what ever you want and camel is able to, e.g. send them as mail, put them in a DB etc.

您不必在你的路线任何额外的处理器或记录的东西现在:

You don't need any extra processors or logging stuff in your route now:

from("...")
.unmarshal(bindyProduct)
.to(...);

这篇关于Apache的骆驼bindy - 如何登录或调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆