Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache camel 模仿Apache Camel DefaultErrorHandler_Apache Camel - Fatal编程技术网

Apache camel 模仿Apache Camel DefaultErrorHandler

Apache camel 模仿Apache Camel DefaultErrorHandler,apache-camel,Apache Camel,我试图使用自定义处理器处理异常。我的路线生成器看起来像这样: onException(Exception.class) .maximumRedeliveries(0) .process(exceptionProcessor) .handled(true) .to("file:C:\\Mahesh\\delete\\failedrequests"); public class ExceptionProcessor implements Processor {

我试图使用自定义处理器处理异常。我的路线生成器看起来像这样:

onException(Exception.class)
    .maximumRedeliveries(0)
    .process(exceptionProcessor)
    .handled(true)
    .to("file:C:\\Mahesh\\delete\\failedrequests");
public class ExceptionProcessor implements Processor 
{
    private static final Logger LOGGER = ExLoggerFactory.getLogger(ExceptionProcessor.class);

    @Override
    public void process(Exchange exchange) throws Exception 
    {
        Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        Object messageHistroy = exchange.getProperty(Exchange.MESSAGE_HISTORY, Object.class);

        LOGGER.error("\n\nMessage History\n---------------------------------------------------------------------------------------------------------------------------------------\n" 
                    + messageHistroy 
                    +"\n\nStacktrace\n---------------------------------------------------------------------------------------------------------------------------------------"
                    );
        ex.printStackTrace();
    }
}
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [file://C:%5CMahesh%5Cdelete%5Ccamelsource                                     ] [       121]
[route1            ] [process1          ] [Processor@0x35a764c7                                                          ] [       120]
[                  ] [to1               ] [file:C:\Mahesh\delete\badworkitems                                            ] [        98]
Message History
---------------------------------------------------------------------------------------------------------------------------------------
[DefaultMessageHistory[routeId=route1, node=process2], DefaultMessageHistory[routeId=null, node=process1]]
我的异常处理器如下所示:

onException(Exception.class)
    .maximumRedeliveries(0)
    .process(exceptionProcessor)
    .handled(true)
    .to("file:C:\\Mahesh\\delete\\failedrequests");
public class ExceptionProcessor implements Processor 
{
    private static final Logger LOGGER = ExLoggerFactory.getLogger(ExceptionProcessor.class);

    @Override
    public void process(Exchange exchange) throws Exception 
    {
        Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        Object messageHistroy = exchange.getProperty(Exchange.MESSAGE_HISTORY, Object.class);

        LOGGER.error("\n\nMessage History\n---------------------------------------------------------------------------------------------------------------------------------------\n" 
                    + messageHistroy 
                    +"\n\nStacktrace\n---------------------------------------------------------------------------------------------------------------------------------------"
                    );
        ex.printStackTrace();
    }
}
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [file://C:%5CMahesh%5Cdelete%5Ccamelsource                                     ] [       121]
[route1            ] [process1          ] [Processor@0x35a764c7                                                          ] [       120]
[                  ] [to1               ] [file:C:\Mahesh\delete\badworkitems                                            ] [        98]
Message History
---------------------------------------------------------------------------------------------------------------------------------------
[DefaultMessageHistory[routeId=route1, node=process2], DefaultMessageHistory[routeId=null, node=process1]]
如您所见,上面我试图模仿的是用户的行为:它首先打印消息历史记录,然后堆栈跟踪

但是,my
ExceptionProcessor
不会以与
DefaultErrorHandler
相同的方式打印消息历史记录<代码>默认错误处理程序按如下方式打印:

onException(Exception.class)
    .maximumRedeliveries(0)
    .process(exceptionProcessor)
    .handled(true)
    .to("file:C:\\Mahesh\\delete\\failedrequests");
public class ExceptionProcessor implements Processor 
{
    private static final Logger LOGGER = ExLoggerFactory.getLogger(ExceptionProcessor.class);

    @Override
    public void process(Exchange exchange) throws Exception 
    {
        Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        Object messageHistroy = exchange.getProperty(Exchange.MESSAGE_HISTORY, Object.class);

        LOGGER.error("\n\nMessage History\n---------------------------------------------------------------------------------------------------------------------------------------\n" 
                    + messageHistroy 
                    +"\n\nStacktrace\n---------------------------------------------------------------------------------------------------------------------------------------"
                    );
        ex.printStackTrace();
    }
}
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [file://C:%5CMahesh%5Cdelete%5Ccamelsource                                     ] [       121]
[route1            ] [process1          ] [Processor@0x35a764c7                                                          ] [       120]
[                  ] [to1               ] [file:C:\Mahesh\delete\badworkitems                                            ] [        98]
Message History
---------------------------------------------------------------------------------------------------------------------------------------
[DefaultMessageHistory[routeId=route1, node=process2], DefaultMessageHistory[routeId=null, node=process1]]
而my
ExceptionProcessor
的打印方式如下:

onException(Exception.class)
    .maximumRedeliveries(0)
    .process(exceptionProcessor)
    .handled(true)
    .to("file:C:\\Mahesh\\delete\\failedrequests");
public class ExceptionProcessor implements Processor 
{
    private static final Logger LOGGER = ExLoggerFactory.getLogger(ExceptionProcessor.class);

    @Override
    public void process(Exchange exchange) throws Exception 
    {
        Exception ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
        Object messageHistroy = exchange.getProperty(Exchange.MESSAGE_HISTORY, Object.class);

        LOGGER.error("\n\nMessage History\n---------------------------------------------------------------------------------------------------------------------------------------\n" 
                    + messageHistroy 
                    +"\n\nStacktrace\n---------------------------------------------------------------------------------------------------------------------------------------"
                    );
        ex.printStackTrace();
    }
}
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [file://C:%5CMahesh%5Cdelete%5Ccamelsource                                     ] [       121]
[route1            ] [process1          ] [Processor@0x35a764c7                                                          ] [       120]
[                  ] [to1               ] [file:C:\Mahesh\delete\badworkitems                                            ] [        98]
Message History
---------------------------------------------------------------------------------------------------------------------------------------
[DefaultMessageHistory[routeId=route1, node=process2], DefaultMessageHistory[routeId=null, node=process1]]
Q.我的处理器似乎无法将第三列处理器和第三行处理器连接到端点。我怎么得到这个

另外,在打印消息历史记录之前,
DefaultErrorHandler
也会打印以下内容:

o.a.camel.processor.DefaultErrorHandler  : Failed delivery for (MessageId: ID-01HW865638-58603-1492677082431-0-7 on ExchangeId: ID-01HW865638-58603-1492677082431-0-8). Exhausted after delivery attempt: 1 caught: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('"' (code 34)): was expecting comma to separate OBJECT entries
at [Source: C:\Mahesh\delete\camelsource\file1.json; line: 4, column: 3]. Processed by failure processor: FatalFallbackErrorHandler[Channel[sendTo(file://C:%5CMahesh%5Cdelete%5Cbadworkitems)]]

Q.如您所见,
DefaultFaultHandler
还可以打印邮件id、交换id、源文件名和发送到文件夹名。我想知道它是从哪里得到这些信息的。对于源文件名,我尝试了所有
Exchange.file.*
属性,但所有打印的
null

只需查看驼峰源代码,它使用您也可以访问的消息历史记录来打印该信息。您可以在github上找到源代码