我创建了一个小型应用程序,它获取日志文件、提取相关数据并将它们推送到数据库中,所有这些都使用骆驼组件。
除非我停止它(优雅关闭),否则它工作得很好。
当我这样做时,spring 会关闭我在 application.yml 中声明的数据源,但由于路由仍在处理文件(飞行中的交换),我会收到很多“数据源已经关闭”的错误。
稍微简化:
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>
有没有办法告诉spring它必须等待camel完全终止才能关闭数据源?
(正如@ClausIbsen 所建议的,jira 创建了: https ://issues.apache.org/jira/browse/CAMEL-14737 )