不立即关闭Web的Sping Boot Camel

cwtwac6a  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(213)

我有一个没有web的apache camel的spring Boot 应用程序,它从一个目录轮询文件并将文件上传到FTP。
Spring Boot 版本:2.7.3
Apache Camel版本:3.18.1
该应用程序在kubernetes中部署为CronJob。
maven pom包含以下依赖项:

<dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-file-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-ftp-starter</artifactId>
        </dependency>

我开发了一个路线构建器:

@Component
public class FtpFileUploaderRouteBuilder extends RouteBuilder {

    private static final String ROUTE_ID = "ftp-file-uploader";

    @Override
    public void configure() throws Exception {

        from("file://data?&initialDelay=100&epeatCount=1")
                .toD("sftp://ftp:21?username=username&password=password");

    }
}

Spring Boot 的主要应用有以下几种:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        final SpringApplication app = new SpringApplication(Application .class);
        app.setWebApplicationType(WebApplicationType.NONE);
        app.setBannerMode(Banner.Mode.OFF);
        System.exit(SpringApplication.exit(app.run(args)));
    }

}

应用程序启动,但立即停止。
我已将以下配置设置为true:camel.springboot.main-run-controller=true,但什么都没有改变。
这是日志:

2022-09-01 14:25:05.731  INFO [ftp-uploader-service,,] 41548 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=f413b668-a57f-38f1-9e52-ff851ced3917
2022-09-01 14:25:09.379  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.18.1 (camel-1) is starting
2022-09-01 14:25:09.403  INFO [ftp-uploader-service,,] 41548 --- [           main] c.s.b.CamelSpringBootApplicationListener : Starting CamelMainRunController to ensure the main thread keeps running
2022-09-01 14:25:09.403  INFO [ftp-uploader-service,,] 41548 --- [inRunController] org.apache.camel.main.MainSupport        : Apache Camel (Main) 3.18.1 is starting
2022-09-01 14:25:09.425  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Routes startup (started:1)
2022-09-01 14:25:09.425  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started ftp-file-uploader (file://target/testfiledir)
2022-09-01 14:25:09.425  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.18.1 (camel-1) started in 401ms (build:129ms init:227ms start:45ms)
2022-09-01 14:25:09.432  INFO [ftp-uploader-service,,] 41548 --- [           main] c.c.g.o.f.ServiceApplication     : Started ServiceApplication in 6.649 seconds (JVM running for 9.108)
2022-09-01 14:25:09.439  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.18.1 (camel-1) is shutting down (timeout:45s)
2022-09-01 14:25:09.452  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Routes stopped (stopped:1)
2022-09-01 14:25:09.452  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Stopped ftp-file-uploader (file://target/testfiledir)
2022-09-01 14:25:09.456  INFO [ftp-uploader-service,,] 41548 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 3.18.1 (camel-1) shutdown in 17ms (uptime:0s)
hs1ihplo

hs1ihplo1#

根据文件
确保CAMEL上下文在独立的 Spring Boot 中运行
要确保Sping Boot 应用程序在停止或JVM终止之前一直保持运行,通常仅在独立运行Spring Boot时需要,即在Web容器保持JVM运行时不使用spring-boot-starter-web,请在配置中设置camel.springboot.main-run-controller=true属性。例如,在application.properties中。


# to keep the JVM running

camel.springboot.main-run-controller = true

相关问题