Camel-Spring Boot:执行后路由不会停止

时间:2016-12-05 03:32:47

标签: spring-boot apache-camel camel-sql

我使用的是Spring Boot + Camel,配置如下。

主要类

 @SpringBootApplication
public class Application extends RouteBuilder {
    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);
    }
    @Override
    public void configure() throws Exception {
        from("sql:{{list.sql}}?dataSource=#dataSource")
        .log("process row ${body}")
        .to("stream:out");
    }}

application.properties

camel.springboot.name=ListJob
camel.springboot.main-run-controller=true

list.sql=<SELECT QUERY>

spring.datasource.driver=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://IP:3306/test
spring.datasource.username=un
spring.datasource.password=pwd

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.abc</groupId>
    <artifactId>wl-event-notification-batch</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>notification</name>
    <description></description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- Camel -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-stream</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-sql</artifactId>
            <version>2.17.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jdbc</artifactId>
            <version>2.17.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot</artifactId>
            <version>2.17.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>2.17.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

My Spring Boot在执行SELECT查询的无限循环中运行路由,因为&#34; camel.springboot.main-run-controller&#34; 属性,直到我点击CNTRL + C.如果我删除了这个属性,应用程序就会立即启动并立即停止路由,而不会完成执行。

有人可以帮助我,让我的路线启动,执行步骤并在运行Spring Boot应用程序时停止吗?

2 个答案:

答案 0 :(得分:0)

添加 .stop()

public void configure() throws Exception {
        from("sql:{{list.sql}}?dataSource=#dataSource")
        .log("process row ${body}")
        .stop();
    }

答案 1 :(得分:0)

您可以使用spring-boot属性:

{{1}}