尝试在 autoStartup 设置为 false 的情况下通过 CamelContext 运行 Camel 路由

问题描述 投票:0回答:1

我有以下 Camel 路线,我试图直接通过 CamelContext 运行,并将 autoStartup 设置为 false @组件

`@ConfigurationProperties()
public class S3IntegratorRoute extends RouteBuilder {

    @Value("${base.url}")
    private String url;

    @Value("#{${queryParams}}")
    private Map<String, String> query;

    @Autowired
    @Qualifier("jsonConversionProcessor")
    private Processor jsonProcessor;

    @Override
    public void configure() throws Exception {

        
        String queryParams = Util.buildQueryParams(query);
        from("timer:mytimer?repeatCount=1").
        // from("timer://manualRestart?repeatCount=1").
        routeId("manualRestart").autoStartup(false).

                setHeader(Exchange.HTTP_QUERY, simple(queryParams)).to(url).process(jsonProcessor);

    }

}
`

我正在尝试在主应用程序类中运行这条路线,如下所示-

@SpringBootApplication
//@EnableDiscoveryClient
public class CollibraApiApplication {

    public static void main(String[] args) throws Exception {
        ApplicationContext ctx = SpringApplication.run(CollibraApiApplication.class, args);

        S3IntegratorRoute s3IntegratorRoute = ctx.getBean(S3IntegratorRoute.class);

        ExtendedCamelContext camelContext = ctx.getBean(ExtendedCamelContext.class);

        camelContext.addRoutes(s3IntegratorRoute);

        camelContext.start();

    }

}

但是当我启动这个 spring boot 应用程序时,我在控制台日志中收到以下消息并且路由没有启动-

] o.a.c.impl.engine.AbstractCamelContext:跳过路线 manualRestart 的开始,因为它配置了 autoStartup=false 2023-03-30 14:41:50.451 [] INFO 25808 --- [ main] o.a.c.impl.engine.AbstractCamelContext : 共有 1 条路线,其中 0 条已启动 2023-03-30 14:41:50.453 [] INFO 25808 --- [ main] o.a.c.impl.engine.AbstractCamelContext:Apache Camel 3.3.0(CamelContext:camel-1)在 0.030 秒内启动

有人可以举例说明如何直接通过 CamelContext 运行这条路线,或者还有其他方法吗?

期望直接运行 Camel Route 而不是 autoStartup

apache-camel spring-camel
1个回答
0
投票

当使用

autoStartup(false)
时,Camel 会 NOT 启动路线,因此当您启动
CamelContext
(Camel 本身)时,如您从日志中看到的那样,将启动 0 条路线。这是意料之中的。如果您想开始路线,请删除
autoStartup
或将其值设置为
true
.

有关更多详细信息,请参阅网站上有关自动启动的文档。

© www.soinside.com 2019 - 2024. All rights reserved.