Apache-Camel:OnCompletion 和 OnException 查询
Apache-Camel : OnCompletion and OnException query
在我的项目中,我想在每个新创建的路由上应用单独的 OnCompletion 和 OnException 处理器。
假设我必须创建 3 条路线。对于每条路线,我准备一个单独的 RouteBuilder class 并进行如下配置 -
onException(Throwable.class).handled(true).process(new ExceptionHandlingProcessor(RouteId)).maximumRedeliveries(2)
.redeliveryDelay(1000).retriesExhaustedLogLevel(LoggingLevel.ERROR)
.retryAttemptedLogLevel(LoggingLevel.WARN);
onCompletion().process(new OnCompletionProcessor(RouteId)) ;
from("sftp:Configuration").routeId("test")
.choice()
.when(body().isEqualTo(null))
.process(new AgeCalculatingProcessor("test"))
.otherwise()
.to("file:configuration").log("Downloaded file ${file:name} complete.")
;
我的问题是....OnException 和 OnCompletion 是否在同一个 Route Builder class 上创建的路由上工作(因为我在每个 RouteBuilder 中只创建一个路由 class) 或者这些将应用于上下文级别并且将适用于所有路由?
实际上我想在路由级别应用 Onexception 和 OnCompletion,但我遇到了异常(比如 - 尝试将 OnException 移动到路由顶部),如果我在每个端点上应用 OnException,如下所示 -
来自(sftp:conf).OnException(Throwable.class).restExceptionconf
.to(文件:conf).OnException(Throwable.class).restExceptionConf
RouteBuilder 级别的 onException:如果你像这样定义 onException 处理程序
onException(...).log("This is RouteBuilder level exception handling.");
configure() {
from(...).to(...);
}
它将处理来自同一 RouteBuilder 中所有路由的异常。
路由级onException:如果你这样定义onException处理程序
configure() {
from(...)
.onException(...).log("This is Route level exception handling.");
.to(...);
}
它将成为路由级别的 onException 处理程序,并且仅用于该单个路由上的异常。
路由级别的 onException 定义将覆盖 RouteBuilder 级别的定义(例如,如果两者都定义了 onException(MyException.class),那么如果在该路由上引发 MyException,则只会调用直接在路由中定义的那个。
onCompletion 的行为方式与 onException 相同。
关于“尝试将 OnException 移动到路由顶部 ”异常:您应该只在路由的开头定义 onException,如下所示:
from(sftp:conf).OnException(Throwable.class).restExceptionconf
.to(file:conf);
在我的项目中,我想在每个新创建的路由上应用单独的 OnCompletion 和 OnException 处理器。
假设我必须创建 3 条路线。对于每条路线,我准备一个单独的 RouteBuilder class 并进行如下配置 -
onException(Throwable.class).handled(true).process(new ExceptionHandlingProcessor(RouteId)).maximumRedeliveries(2)
.redeliveryDelay(1000).retriesExhaustedLogLevel(LoggingLevel.ERROR)
.retryAttemptedLogLevel(LoggingLevel.WARN);
onCompletion().process(new OnCompletionProcessor(RouteId)) ;
from("sftp:Configuration").routeId("test")
.choice()
.when(body().isEqualTo(null))
.process(new AgeCalculatingProcessor("test"))
.otherwise()
.to("file:configuration").log("Downloaded file ${file:name} complete.")
;
我的问题是....OnException 和 OnCompletion 是否在同一个 Route Builder class 上创建的路由上工作(因为我在每个 RouteBuilder 中只创建一个路由 class) 或者这些将应用于上下文级别并且将适用于所有路由?
实际上我想在路由级别应用 Onexception 和 OnCompletion,但我遇到了异常(比如 - 尝试将 OnException 移动到路由顶部),如果我在每个端点上应用 OnException,如下所示 -
来自(sftp:conf).OnException(Throwable.class).restExceptionconf .to(文件:conf).OnException(Throwable.class).restExceptionConf
RouteBuilder 级别的 onException:如果你像这样定义 onException 处理程序
onException(...).log("This is RouteBuilder level exception handling.");
configure() {
from(...).to(...);
}
它将处理来自同一 RouteBuilder 中所有路由的异常。
路由级onException:如果你这样定义onException处理程序
configure() {
from(...)
.onException(...).log("This is Route level exception handling.");
.to(...);
}
它将成为路由级别的 onException 处理程序,并且仅用于该单个路由上的异常。
路由级别的 onException 定义将覆盖 RouteBuilder 级别的定义(例如,如果两者都定义了 onException(MyException.class),那么如果在该路由上引发 MyException,则只会调用直接在路由中定义的那个。
onCompletion 的行为方式与 onException 相同。
关于“尝试将 OnException 移动到路由顶部 ”异常:您应该只在路由的开头定义 onException,如下所示:
from(sftp:conf).OnException(Throwable.class).restExceptionconf
.to(file:conf);