处理Apache Camel消费者错误。

3
我希望在用户凭据更改的情况下停止路由,为此我想处理javax.mail.AuthenticationFailedException.class,但这并没有起作用。
from(_getImapSentURL(emailConfiguration)).routeId(routeIdSent)
            .onException(javax.mail.AuthenticationFailedException.class)
            .process(new EmailErrorHandler()).end()
            .process(new EmailContentSentProcessor(user, filterSent));

错误处理器
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");
    }
}

在控制台中我看到了这个异常,但是它没有被处理。

哪里出现了错误?

解决方案:

在终端点URL中添加参数consumer.bridgeErrorHandler=true

在路由构建器中添加异常处理程序

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

实现ExceptionHandler 如果将handle(..)设置为true,则只能通过这种方式访问异常

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

关于Apache Camel文档中提到的问题:

1个回答

3
这就像鸡生蛋、蛋生鸡的问题。当您有一个有效的消息要路由而在路由过程中发生错误时,Camel错误处理程序会做出反应。
但是由于邮件接收者无法登录,则没有有效的消息可路由。
但是您可以打开一个选项,将消费者与Camel错误处理程序桥接。您可以从这里找到更多详细信息: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以及它所引用的链接。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接