gpt4 book ai didi

java - 处理 apache camel 消费者错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:19:01 27 4
gpt4 key购买 nike

我想在用户凭据更改的情况下停止路由,为此我想处理 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

最佳答案

这就像先有鸡还是先有蛋的情况。当您有一条有效消息要路由时,Camel 错误处理程序会使用react,然后在路由期间发生一些错误。

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

但是您可以打开一个选项,将消费者与 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及其引用的链接

关于java - 处理 apache camel 消费者错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31185913/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com