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)