1

I created a small application that fetches log files, extract relevant data and push them in a database, all using camel components.

It works pretty well unless when I stop it (gracefull shutdown).
When I do so, spring closes the datasource I declared in the application.yml but as there are still files being processed (inflight exchanges) by the route, I get lots of "datasource already closed" errors.

slightly simplified :

public class LogToDb extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("sftp:user@host.com/logs?password=T0pS3cret?include=.*\.gz")
            .unmarshal().gzipDeflater()
            .split(body().tokenize("\n")).streaming()
            .filter(bodyAs(String.class).contains("interesting line"))
            .bean(new LineToAttributesMap())
            .to("sql:INSERT INTO myTable(date, id, duration) values (:#date, :#id, :#duration)");
    }
}
camel:
  springboot:
    main-run-controller: true
spring:
  datasource:
    url: jdbc:postgresql://localhost:5433/myDb
    hikari:
      driver-class-name: org.postgresql.Driver
      password: ********
      username: postgres
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/>
    </parent>
    <!-- <groupid />, <artifactId />, <version /> ... -->
    <properties>
        <java.version>11</java.version>
        <camel.version>3.0.1</camel.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-ftp</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-sql-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <!-- ... non-relevant dependencies omited for brevity... -->
    </dependencies>
</project>

Is there a way to tell spring that it must wait for camel to be completely terminated before it can close the datasource ?

(as suggested by @ClausIbsen, jira created: https://issues.apache.org/jira/browse/CAMEL-14737)

Ghurdyl
  • 877
  • 12
  • 17
  • What version of Spring Boot and Camel are you using ? – Claus Ibsen Mar 12 '20 at 19:06
  • @ClausIbsen I added a slice of the pom, basically spring-boot 2.2.5 and camel 3.0.1 – Ghurdyl Mar 13 '20 at 09:03
  • Try with Camel 3.1.0 – Claus Ibsen Mar 14 '20 at 06:15
  • @ClausIbsen I tried with camel 3.1.0 as suggested but I have the same behavior – Ghurdyl Mar 18 '20 at 07:23
  • Can you create a JIRA ticket. I think we need to see if we can add some code in camel-spring-boot to ensure spring boot will shutdown camel last. – Claus Ibsen Mar 18 '20 at 19:05
  • @ClausIbsen Sure I can open a ticket, however I think it's the other way around. Camel should stopped first and spring should wait for the last inflight message to be completed before it closes the other beans (especially the datasource bean here) – Ghurdyl Mar 19 '20 at 07:16

0 Answers0