Docker容器中的Spring集成FTP:未触发流
我花了很长时间才弄清楚我的问题是从哪里来的。我可以在本地运行,我已经构建了我的Docker容器中的Spring集成FTP:未触发流,spring,docker,spring-integration,spring-integration-dsl,spring-integration-ftp,Spring,Docker,Spring Integration,Spring Integration Dsl,Spring Integration Ftp,我花了很长时间才弄清楚我的问题是从哪里来的。我可以在本地运行,我已经构建了我的.jar,并且在本地运行 我的集成流程设置如下 @Bean IntegrationFlow integrationFlow(final DataSource datasource) { return IntegrationFlows.from( Ftp.inboundStreamingAdapter(template()) .remoteDirectory("/folder/")
.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;
}
我打开DEBUG
并观察输出
在本地运行并运行构建的.jar
,我可以看到轮询器正在工作,它会触发对在我的远程数据库(postgresql)中创建的元数据存储表的SQL查询
在docker容器中运行时,我没有看到正在运行的sql查询。这告诉我问题就在这里的某个地方
无论在本地运行、运行内置的.jar
还是在docker容器中运行,控制台中的启动日志上的调试都是相同的INFO
s和WARN
s。
这里有一条信息消息可能会有所帮助
Bean with key 'metadataStore' has been registered as an MBean but has no exposed attributes or operations
通过尝试连接到无效主机,我检查了是否存在隐藏的SessionFactory
连接问题,但我的docker容器中确实存在无效主机的异常。因此,我可以自信地说,FTP连接是有效的,并且使用正确的主机和端口运行
我认为这与民意调查或我的数据源有关
在这个应用程序中,我还使用JDBC和JPA运行SpringDataREST,在不同库中使用DataSourceBean会有任何问题吗
任何帮助或指导都将不胜感激 因此,
DefaultFtpSessionFactory
的默认客户端模式是“主动”,但在我的情况下,在docker容器内,客户端模式必须设置为“被动”
为此,我需要向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;
}
@Bean
公共会话工厂ftpSessionFactory(){
DefaultFtpSessionFactory sf=新的DefaultFtpSessionFactory();
sf.setHost(主机);
sf.设置端口(端口);
sf.setUsername(用户名);
sf.setPassword(密码);
sf.setClientMode(2);
返回sf;
}
exec
插入容器并尝试ping ftp服务器。看起来ftp服务器地址没有从容器中解析。@AvinashReddy我在docker容器中安装了lftp,并成功连接到ftp服务器……另外,在启动日志中看到此INFO
项为“metadataStore”的Bean已注册为MBean,但没有公开的属性或操作
@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;
}