简体   繁体   English

处理apache骆驼消费者的错误

[英]Handle apache camel consumer errors

I want to stop route in case if user credentials changed, for this I want to handle javax.mail.AuthenticationFailedException.class but this does not work: 如果用户凭据更改,我想停止路由,为此我想处理javax.mail.AuthenticationFailedException.class但这不起作用:

from(_getImapSentURL(emailConfiguration)).routeId(routeIdSent)
            .onException(javax.mail.AuthenticationFailedException.class)
            .process(new EmailErrorHandler()).end()
            .process(new EmailContentSentProcessor(user, filterSent));

and error processor 和错误处理器

public class EmailErrorHandler implements Processor {
    private static final long serialVersionUID = 1L;

    Logger logger = Logger.getLogger(getClass());

    @Override
    public void process(Exchange exchange) throws Exception {
        logger.info("handled");
    }
}

In console I'm getting this exception but it's not handled. 在控制台中我得到了这个异常,但它没有得到处理。

Where is the mistake? 哪里出错了?

Solution: 解:

Add param to endpoint URL consumer.bridgeErrorHandler=true 将param添加到端点URL consumer.bridgeErrorHandler=true

In route builder add exception handler 在路径构建器中添加异常处理程

onException(Exception.class)
            .log("Exception occurred due: ${exception.message}")
            .bean(new EmailConsumerExceptionHandler(), "handleException").handled(true)
            .end();

Implement ExceptionHandler Also if you set handle(..) to true you can access to exception only in this way 实现ExceptionHandler此外,如果将handle(..)设置为true,则只能以这种方式访问​​异常

Exception cause = originalExchange.getProperty(
            Exchange.EXCEPTION_CAUGHT, Exception.class);

in reffer to Apache camel documentation 请参阅Apache骆驼文档

Its like a chicken and egg situation. 它像鸡和鸡蛋的情况。 The Camel error handler reacts when you have a valid message to route and then during routing some error happens. 当您有有效的消息要路由时,Camel错误处理程序会做出反应,然后在路由期间会发生一些错误。

But as the mail consumer cannot login then there is no valid message to route. 但由于邮件消费者无法登录,因此没有有效的消息要路由。

But you can turn on an option to bridge the consumer with Camels error handler. 但是您可以启用一个选项来使用Camels错误处理程序来桥接使用者。 You can find more details from here: http://camel.apache.org/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.html and the links it refers to 您可以在此处找到更多详细信息: http//camel.apache.org/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the- file-consumer-use-the-camel-error-handler.html及其引用的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM