http://jira.mfd.msk:8088/browse/CLS-428 dbf-importer SFTP support
This commit is contained in:
parent
c4416f2034
commit
aea33dcd13
4 changed files with 136 additions and 0 deletions
|
|
@ -30,6 +30,10 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.integration</groupId>
|
||||||
|
<artifactId>spring-integration-sftp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- JDBC -->
|
<!-- JDBC -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
package ru.spcex.clearing.dbf.importer.config;
|
||||||
|
|
||||||
|
import com.jcraft.jsch.ChannelSftp;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.integration.annotation.InboundChannelAdapter;
|
||||||
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
import org.springframework.integration.core.MessageSource;
|
||||||
|
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
||||||
|
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||||
|
import org.springframework.integration.scheduling.PollerMetadata;
|
||||||
|
import org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizer;
|
||||||
|
import org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizingMessageSource;
|
||||||
|
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
|
||||||
|
import org.springframework.messaging.MessageHandler;
|
||||||
|
import org.springframework.scheduling.support.PeriodicTrigger;
|
||||||
|
import ru.spcex.clearing.dbf.importer.config.settings.ImportDBFServiceSettings;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SFTPConfig {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private final ImportDBFServiceSettings settings;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public SFTPConfig(ImportDBFServiceSettings settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
||||||
|
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||||
|
factory.setHost(settings.getStore().getServerIp());
|
||||||
|
factory.setPort(settings.getStore().getServerPort());
|
||||||
|
factory.setUser(settings.getStore().getUser());
|
||||||
|
factory.setPassword(settings.getStore().getPassword());
|
||||||
|
factory.setAllowUnknownKeys(true);
|
||||||
|
return new CachingSessionFactory<>(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = PollerMetadata.DEFAULT_POLLER)
|
||||||
|
public PollerMetadata defaultPoller() {
|
||||||
|
PollerMetadata pollerMetadata = new PollerMetadata();
|
||||||
|
pollerMetadata.setTrigger(new PeriodicTrigger(5, TimeUnit.SECONDS));
|
||||||
|
return pollerMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
|
||||||
|
SftpInboundFileSynchronizer fileSync = new SftpInboundFileSynchronizer(sftpSessionFactory());
|
||||||
|
fileSync.setDeleteRemoteFiles(true);
|
||||||
|
fileSync.setTemporaryFileSuffix(".tmp");
|
||||||
|
fileSync.setRemoteDirectory(settings.getStore().getSftpSrcDir());
|
||||||
|
return fileSync;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@InboundChannelAdapter("sftpChannel")
|
||||||
|
public MessageSource<File> sftpMessageSource() {
|
||||||
|
SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer());
|
||||||
|
source.setLocalDirectory(new File(settings.getStore().getSrcDir()));
|
||||||
|
source.setAutoCreateLocalDirectory(true);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ServiceActivator(inputChannel="sftpChannel")
|
||||||
|
MessageHandler messageHandler() {
|
||||||
|
return arg0 -> {
|
||||||
|
File f = (File) arg0.getPayload();
|
||||||
|
log.info("copy file '{}' from sftp event", f.getName());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,12 @@ public class Store {
|
||||||
private String outDir;
|
private String outDir;
|
||||||
private String outDirError;
|
private String outDirError;
|
||||||
private boolean deleteSrcFiles = true;
|
private boolean deleteSrcFiles = true;
|
||||||
|
//sftp settings
|
||||||
|
private String sftpSrcDir;
|
||||||
|
private String user;
|
||||||
|
private String password;
|
||||||
|
private String serverIp;
|
||||||
|
private int serverPort;
|
||||||
|
|
||||||
public String getSrcDir() {
|
public String getSrcDir() {
|
||||||
return srcDir;
|
return srcDir;
|
||||||
|
|
@ -38,4 +44,44 @@ public class Store {
|
||||||
public void setOutDirError(String outDirError) {
|
public void setOutDirError(String outDirError) {
|
||||||
this.outDirError = outDirError;
|
this.outDirError = outDirError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerIp() {
|
||||||
|
return serverIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerIp(String serverIp) {
|
||||||
|
this.serverIp = serverIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getServerPort() {
|
||||||
|
return serverPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerPort(int serverPort) {
|
||||||
|
this.serverPort = serverPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSftpSrcDir() {
|
||||||
|
return sftpSrcDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSftpSrcDir(String sftpSrcDir) {
|
||||||
|
this.sftpSrcDir = sftpSrcDir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,13 @@ import-dbf-service.common.encoding-source=cp866
|
||||||
import-dbf-service.common.insert-batch-size=100
|
import-dbf-service.common.insert-batch-size=100
|
||||||
import-dbf-service.common.threads-count=10
|
import-dbf-service.common.threads-count=10
|
||||||
|
|
||||||
|
#sftpSrcDir
|
||||||
|
import-dbf-service.store.sftp-src-dir=clearing_importer_sftp
|
||||||
|
import-dbf-service.store.user=user
|
||||||
|
import-dbf-service.store.password=*********
|
||||||
|
import-dbf-service.store.server-ip=127.0.0.1
|
||||||
|
import-dbf-service.store.server-port=22
|
||||||
|
|
||||||
import-dbf-service.hazelcast.cluster-members=10.200.200.181:5701
|
import-dbf-service.hazelcast.cluster-members=10.200.200.181:5701
|
||||||
import-dbf-service.hazelcast.login=dev
|
import-dbf-service.hazelcast.login=dev
|
||||||
import-dbf-service.hazelcast.password=dev-pass
|
import-dbf-service.hazelcast.password=dev-pass
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue