首页 > 解决方案 > Apache Camel 3.0.1 无法启动并消耗路由器到 FTPs 文件夹

问题描述

我正在使用 Apache Camel FTP 3.0.1 和 Spring Boot 来连接和侦听 FTP 远程文件夹上的文件创建事件。它适用于我的本地 FTP 服务器(我还没有在我的本地 docker 上使用 FTP)。但是当我连接到 FTPs 服务器时,它无法启动和消耗路由器。

这是我的代码:

@Component
public class ListenerSyncDataRouter extends RouteBuilder {

    Logger logger = LoggerFactory.getLogger(ListenerSyncDataRouter.class);

    @Autowired
    ListenerSyncDataFileProcessor listenerSyncDataFileProcessor;

    @Override
    public void configure() throws Exception {
        from("ftps://user@ftps_server_ip:21/ReceiveDataFile/Processing?password=xxx&ftpClient.trustStore.file=keys/diode.jks&ftpClient.trustStore.password=xxx&passiveMode=true&include=.*.xml&filter=#ftpFileFilter&move=ReceiveDataFile/Temp&maxMessagesPerPoll=200&throwExceptionOnConnectFailed=true&soTimeout=3000")
                .log("${body}")
                .log(LoggingLevel.INFO, "Processing ${id}")
                .process(listenerSyncDataFileProcessor)
                .end();
    }
}

我得到异常日志:

[INFO ] 2021-01-23 19:58:31.413 [main] SpringBootRoutesCollector - Loading additional Camel XML routes from: classpath:camel/*.xml
[INFO ] 2021-01-23 19:58:31.413 [main] SpringBootRoutesCollector - Loading additional Camel XML rests from: classpath:camel-rest/*.xml
[INFO ] 2021-01-23 19:58:31.420 [main] SpringBootCamelContext - Apache Camel 3.0.1 (CamelContext: camel-1) is starting
[INFO ] 2021-01-23 19:58:31.421 [main] JmxManagementStrategy - JMX is enabled
[INFO ] 2021-01-23 19:58:31.650 [main] SpringBootCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html

日志停止于Apache Camel 3.0.1 (CamelContext: camel-1) is starting路由器,而不是启动和消耗。

这是我本地 FTP 服务器的正常日志:

用于连接本地 FTP 服务器的 FTP URI:ftp://ftpuser@localhost:21/files?filter=%23ftpFileFilter&include=.*.xml&move=files%2Ftemp&passiveMode=true&password=xxxxxx

[INFO ] 2021-01-23 19:53:45.474 [main] SpringBootRoutesCollector - Loading additional Camel XML routes from: classpath:camel/*.xml
[INFO ] 2021-01-23 19:53:45.474 [main] SpringBootRoutesCollector - Loading additional Camel XML rests from: classpath:camel-rest/*.xml
[INFO ] 2021-01-23 19:53:45.481 [main] SpringBootCamelContext - Apache Camel 3.0.1 (CamelContext: camel-1) is starting
[INFO ] 2021-01-23 19:53:45.481 [main] JmxManagementStrategy - JMX is enabled
[INFO ] 2021-01-23 19:53:45.727 [main] SpringBootCamelContext - StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
[INFO ] 2021-01-23 19:53:46.047 [main] SpringBootCamelContext - Route: route1 started and consuming from: ftp://ftpuser@localhost:21/files?filter=%23ftpFileFilter&include=.*.xml&move=files%2Ftemp&passiveMode=true&password=xxxxxx
[INFO ] 2021-01-23 19:53:46.090 [main] SpringBootCamelContext - Route: route2 started and consuming from: ftp://ftpuser@localhost:21/logs?filter=%23ftpFileFilter&include=.*.json&move=logs%2Ftemp&passiveMode=true&password=xxxxxx
[INFO ] 2021-01-23 19:53:46.093 [main] SpringBootCamelContext - Total 2 routes, of which 2 are started
[INFO ] 2021-01-23 19:53:46.094 [main] SpringBootCamelContext - Apache Camel 3.0.1 (CamelContext: camel-1) started in 0.613 seconds
[INFO ] 2021-01-23 19:53:46.099 [main] ListenerApplication - Started ListenerApplication in 3.811 seconds (JVM running for 4.866)
Directory Change Listener running...

它不会获取启动和使用路由器的日志,因为它与本地 FTP 一起运行,因此它无法注册路由器并侦听 FTPs 文件夹上的文件创建事件。

我的代码有什么问题?

标签: javaspring-bootftpapache-camelftps

解决方案


我建议您调查ReceiveDataFile是否是 FTP 用户主目录中的目录。

Camel FTP 组件中所述:

不支持绝对路径。Camel 通过从目录名中修剪所有前导斜杠来将绝对路径转换为相对路径。日志中将打印 WARN 消息。


推荐阅读