You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kotlin+Quarkus环境下使用Camel AdviceWith测试路由时启动异常问题咨询

Kotlin+Quarkus环境下使用Camel AdviceWith测试路由时启动异常问题咨询

我正在尝试为我的Camel路由编写测试,使用的是Kotlin+Quarkus技术栈。

我发现CamelContext会在我自己的生产路由RouteBuilder之前运行AdviceWithRouteBuilder,导致测试启动失败。我初始化Advice的代码如下:

fun configureMockEventTopicEndpoint() {
    AdviceWith.adviceWith(
        "event-collector",
        context,
        ReplaceDirectThem()
    )
}

class ReplaceDirectThem : AdviceWithRouteBuilder() {
    override fun configure() {
        replaceFromWith("direct:abc")
        interceptSendToEndpoint("jms:topic:*")
            .skipSendToOriginalEndpoint()
            .to("mock:jms:topic:someTopic")
    }
}

这种情况下会抛出以下异常:

Caused by: java.lang.IllegalArgumentException: originalRoute must be
specified on: Routes: []

很明显这是因为这段代码在我实际的路由构建器之前运行了。当我改成Kotlin的匿名内部类写法后:

fun configureEventTopicEndpoint() {
    AdviceWith.adviceWith(
        "event-collector",
        context,
        object : AdviceWithRouteBuilder() {
            override fun configure() {
                replaceFromWith("direct:abc")
                interceptSendToEndpoint("jms:topic:*")
                    .skipSendToOriginalEndpoint()
                    .to("mock:jms:topic:sendstuff")
            }
        }
    )
}

此时又会抛出另一个异常:

class org.apache.camel.support.ObjectHelper cannot access a member of
class .....CamelRoutesTest$configureMockEventTopicEndpoint$1 with
modifiers ""

我到底哪里弄错了?

我已经尝试了上面描述的两种方式,还查看了Camel的源码,发现MainConfigurationProperties.routeBuilders会优先加载我的测试路由构建器,而不是生产环境的路由。

我的期望是生产路由先运行,然后再执行测试路由构建器,这样才能对生产路由进行修改,最终让测试成功通过。

备注:内容来源于stack exchange,提问作者Ali Yüce

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 10:09:52