【问题标题】:Handle apache camel consumer errors处理 apache camel 消费者错误
【发布时间】:2015-07-02 13:26:00
【问题描述】:

如果用户凭据发生更改,我想停止路由,为此我想处理 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 documentation

【问题讨论】:

    标签: java apache-camel


    【解决方案1】:

    这就像鸡和蛋的情况。 Camel 错误处理程序会在您有一条有效消息要路由时做出反应,然后在路由期间发生一些错误。

    但是由于邮件消费者无法登录,因此没有有效的消息可以路由。

    但是您可以打开一个选项以将消费者与 Camels 错误处理程序联系起来。您可以从这里找到更多详细信息: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 及其引用的链接

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-25
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多