首页 > 解决方案 > Apache Camel Route 正在自动启动

问题描述

当我启动主类时,路由加载文件会自动启动。

在异常情况下,进程应该何时完成。它一次又一次地启动loadfile。

它应该从定时器开始,然后应该调用 loadfile 路由,但是 loadfile 是独立启动的,也从定时器开始。

CamelContext context = new DefaultCamelContext(sr);
try {

        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                onException(Exception.class)
                        .log(LoggingLevel.INFO, "Extype:${exception.message}")
                        .stop();

                from("timer://alertstrigtimer?period=60s&repeatCount=1")
                        .startupOrder(1)
                        .log(LoggingLevel.INFO, "*******************************Job-Alert-System: Started: alertstrigtimer******************************")
                        .to("direct:loadFile").stop();

                from("direct:loadFile").routeId("loadfile")
                         .log(LoggingLevel.INFO, "*******************************Job-Alert-System: Started: direct:loadFile******************************")
                         .from(getTriggerFileURI(getWorkFilePath(), getWorkFileName())).choice()

              .
              .
         });
        context.start();
        Thread.sleep(40000);

以下是日志:

[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) is starting
[main] INFO org.apache.camel.management.ManagedManagementStrategy - JMX is enabled
[main] INFO org.apache.camel.impl.converter.DefaultTypeConverter - Type converters loaded (core: 194, classpath: 14)
[main] INFO org.apache.camel.impl.DefaultCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: timer://alertstrigtimer?period=60s&repeatCount=1
[main] INFO org.apache.camel.impl.DefaultCamelContext - Skipping starting of route loadfile as its configured with autoStartup=false
[main] INFO org.apache.camel.impl.DefaultCamelContext - Route: loadDataAndAlerts started and consuming from: direct://loadDataAndAlerts
[main] INFO org.apache.camel.impl.DefaultCamelContext - Total 4 routes, of which 2 are started
[main] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.21.1 (CamelContext: camel-1) started in 0.761 seconds
[Camel (camel-1) thread #1 - timer://alertstrigtimer] INFO route1 - *******************************Job-Alert-System: Started: alertstrigtimer******************************
[Camel (camel-1) thread #2 - timer://alertstrigtimer] INFO loadfile - *******************************Job-Alert-System: Started: direct:loadFile******************************
[Camel (camel-1) thread #1 - file://null] INFO loadfile - *******************************Job-Alert-System: Started: direct:loadFile******************************

标签: javaapache-camel

解决方案


问题可能是由.from(getTriggerFileURI(getWorkFilePath(), getWorkFileName()))loadfile 路由中的这一行引起的。具有多个来自端点的路由称为多输入,并且此模式已在 Camel 3.x 中删除

红帽

from("URI1").from("URI2").from("URI3").to("DestinationUri");

...,来自每个输入端点 URI1、URI2 和 URI3 的交换彼此独立并在单独的线程中处理。实际上,您可以将前面的路由视为等效于以下三个单独的路由:

from("URI1").to("DestinationUri");

from("URI2").to("DestinationUri");

from("URI3").to("DestinationUri");

不要使用来自端点的多个(额外的独立输入),而是尝试内容丰富器模式(pollEnrich用于文件组件)。


推荐阅读