gpt4 book ai didi

exception - Apache Camel 错误因为必须在 : process? 上指定 ref

转载 作者:行者123 更新时间:2023-12-04 17:37:31 27 4
gpt4 key购买 nike

我想要做的是阅读邮件收件箱并查找主题行包含“错误”一词的电子邮件。

如果它找到一封主题行中没有“ERROR”字样的电子邮件,那么它必须转到 onException 过程。

它一直工作到某个时候,我认为它尝试处理,然后我收到错误。

public class MailRouteBuilder extends RouteBuilder {

@Autowired
ExceptionMailProcessor exceptionMailProcessor;

@Override
public void configure() throws Exception {
String mailRouteStr = "imap://host.......";

List<String> tmpKeywords = new ArrayList<>();
tmpKeywords.add("ERROR"):

onException(MailRouteException.class, RuntimeException.class).log(LoggingLevel.ERROR, "EXCEPTION in MAIL")
.process(exceptionMailProcessor)
.end();

from(mailRouteStr).routeId("mymail")
.validate(header("subject").in(tmpKeywords))
.log("Sending to Mail Queue")
.to("{{jmsMailIn}}")
.log("Done with Mail Queue")
.end();
}
.
.
.

我的 ExceptionMailProcessor 类。
@Component
public class ExceptionMailProcessor implements Processor {

@Override
public void process(Exchange exchange) throws Exception {

String messageBody;
Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);

}
}


错误:
org.apache.camel.FailedToCreateRouteException: Failed to create route mymail at: >>> OnException[[class MailRouteException, class java.lang.RuntimeException] -> [Log[EXCEPTION in MAIL], process[Processor@0x0]]] <<< in route: Route(mymail)[[From[imap://mai... because of ref must be specified on: process[Processor@0x0]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1352)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:212)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1140)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3735)
at org.apache.camel.impl.DefaultCamelContext.addRouteDefinitions(DefaultCamelContext.java:1072)
at org.apache.camel.builder.RouteBuilder.populateRoutes(RouteBuilder.java:478)
at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:391)
at org.apache.camel.impl.DefaultCamelContext$3.call(DefaultCamelContext.java:1024)
at org.apache.camel.impl.DefaultCamelContext$3.call(DefaultCamelContext.java:1021)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3267)
at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:1021)
at com.agile.net.international.mc360.routing.routebuilder.process.mail.MailRouteProcess.lambda$checkMailDataSourceRoutes$0(MailRouteProcess.java:135)
at java.util.HashMap.forEach(HashMap.java:1289)
at com.agile.net.international.mc360.routing.routebuilder.process.mail.MailRouteProcess.checkMailDataSourceRoutes(MailRouteProcess.java:131)
at com.agile.net.international.mc360.routing.routebuilder.process.mail.MailRouteProcess.process(MailRouteProcess.java:60)
at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:197)
at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:79)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.IllegalArgumentException: ref must be specified on: process[Processor@0x0]
at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:340)
at org.apache.camel.model.ProcessDefinition.createProcessor(ProcessDefinition.java:99)
at org.apache.camel.model.ProcessorDefinition.createProcessor(ProcessorDefinition.java:518)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessorImpl(ProcessorDefinition.java:481)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:448)
at org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:186)
at org.apache.camel.model.OnExceptionDefinition.addRoutes(OnExceptionDefinition.java:210)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1349)
... 22 more

错误中的类 MailRouteProcess 正是我构建 imap 字符串并将其添加到 Camel 上下文的地方。

我想要的只是当 Route 失败时,它会转到 ExceptionMailProcessor。在那里我会做一些事情,实际的邮件消息必须标记为 READ 并且不再处理。

最佳答案

与其尝试在 ExceptionMailProcessor 的实例中 Autowiring ,不如尝试将其作为 DSL 中的 bean 进行引用。通常对于 Camel 中的处理器,我使用 Spring Configuration 类将处理器注册为 bean,然后在 DSL 中引用它们:

@Configuration
public class AppConfig {

@Bean(name = "ExceptionMailProcessor ")
public ExceptionMailProcessor exceptionMailProcessor() {
return new ExceptionMailProcessor();
}
}

然后在您的 Camel DSL 中,您可以像这样引用它:
onException(MailRouteException.class, RuntimeException.class).log(LoggingLevel.ERROR, "EXCEPTION in MAIL")
.to("bean:ExceptionMailProcessor")
.end();

关于exception - Apache Camel 错误因为必须在 : process? 上指定 ref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56112854/

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