Docker容器中的Spring Integration FTP:未触发流程

问题描述 投票:0回答:1

我花了很多时间弄清楚我的问题的根源。我可以在本地运行,也可以构建.jar并在本地运行。

我的整合流程如下

@Bean
IntegrationFlow integrationFlow(final DataSource datasource) {
return IntegrationFlows.from(
    Ftp.inboundStreamingAdapter(template())
        .remoteDirectory("/folder/")
        .patternFilter("file_name.txt")
        .filter(
            new FtpPersistentAcceptOnceFileListFilter(metadataStore(datasource), "")),
    spec -> spec.poller(Pollers.fixedDelay(5, TimeUnit.SECONDS)))
    .transform(streamToBytes())
    .handle(handler())
    .get()
}

@Bean
FtpRemoteFileTemplate template() {
  return new FtpRemoteFileTemplate(ftpSessionFactory());
}

@Bean
public StreamTransformer streamToBytes() {
  return new StreamTransformer(); // transforms to byte[]
}

@Bean
public ConcurrentMetadataStore metadataStore(final DataSource dataSource) {
  return new JdbcMetadataStore(dataSource);
}

@Bean
public SessionFactory<FTPFile> ftpSessionFactory() {
  DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
  sf.setHost(host);
  sf.setPort(port);
  sf.setUsername(userName);
  sf.setPassword(password);
  return sf;
}

我在我的application.yml中设置了数据源和ftp信息

当我在本地运行时,我没有问题。当我运行gradle build并使用几个不同的openjdk版本(8u181、8u191、11.04)运行我的.jar时,我没有任何问题。

[当我使用.jar文件在Docker容器中运行时,出现问题。

我的Docker文件

FROM openjdk:8u212-jdk-alpine
WORKDIR /app

COPY build/libs/app-1.0.jar .

RUN apk add --update ttf-dejavu && rm -rf /var/cache/apk/*

ENTRYPOINT ["java", "-jar", "app-1.0.jar"]

我打开了DEBUG,并观看了输出。

在本地运行并运行内置的.jar,我可以看到轮询器正在工作,并且它触发了对在我的远程数据库(postgresql)中创建的metasStore表的SQL查询。

在docker容器中运行,我看不到正在运行的sql查询。告诉我问题所在。

在调试时,无论在本地运行,运行内置的INFO还是在Docker容器中运行,控制台中的启动日志都是相同的WARN.jar。有此信息消息可能会有所帮助

Bean with key 'metadataStore' has been registered as an MBean but has no exposed attributes or operations

我通过尝试连接到无效主机来检查是否存在隐藏的SessionFactory连接问题,但是我确实在我的docker容器中收到了无效主机的异常。因此,我可以自信地说FTP连接有效并且可以在正确的主机和端口上运行。

我认为这与轮询器或我的数据源有关。

在此应用程序内部,我也在使用JDBC和JPA运行Spring Data Rest,在不同库中使用数据源bean是否会出现问题?

任何帮助或指导,将不胜感激。

spring docker spring-integration spring-integration-dsl spring-integration-ftp
1个回答
0
投票

因此DefaultFtpSessionFactory的默认客户端模式为“ ACTIVE”,但在我的情况下,在Docker容器内部,客户端模式必须设置为“ PASSIVE”]]

为此,我需要向DefaultFtpSessionFactory添加一行代码您必须将客户端模式设置为2 ...sf.setClientMode(2);下面是最终的DefaultFtpSessionFactory bean。

@Bean
public SessionFactory<FTPFile> ftpSessionFactory() {
  DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
  sf.setHost(host);
  sf.setPort(port);
  sf.setUsername(userName);
  sf.setPassword(password);
  sf.setClientMode(2);

  return sf;
}
© www.soinside.com 2019 - 2024. All rights reserved.