spring-boot - Spring Integration Sftp:有时需要超过 15 分钟才能完成操作
问题描述
我正在使用 Spring 集成 sftp 将文件放在远程服务器上,下面是配置。
<spring-integration.version>5.2.5.RELEASE</spring-integration.version>
我已经配置了@MessagingGateway。
@MessagingGateway
public interface SftpMessagingGateway {
@Gateway(requestChannel = "sftpOutputChannel")
void sendToFTP(Message<?> message);
}
我已将 MessageHandler 配置如下,
@Bean
@ServiceActivator(inputChannel = "sftpOutputChannel" )
public MessageHandler genericOutboundhandler() {
SftpMessageHandler handler = new SftpMessageHandler(outboundTemplate(), FileExistsMode.APPEND);
handler.setRemoteDirectoryExpressionString("headers['remote_directory']");
handler.setFileNameGenerator((Message<?> message) -> ((String) message.getHeaders().get(Constant.FILE_NAME_KEY)));
handler.setUseTemporaryFileName(false);
return handler;
}
我已经配置了 SftpRemoteFileTemplate 如下
private SftpRemoteFileTemplate outboundTemplate;
public SftpRemoteFileTemplate outboundTemplate(){
if (outboundTemplate == null) {
outboundTemplate = new SftpRemoteFileTemplate(sftpSessionFactory());
}
return outboundTemplate;
}
这是 SessionFactory 的配置
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
factory.setHost(host);
factory.setPort(port);
factory.setUser(username);
factory.setPassword(password);
factory.setAllowUnknownKeys(true);
factory.setKnownHosts(host);
factory.setSessionConfig(configPropertiesOutbound());
CachingSessionFactory<LsEntry> csf = new CachingSessionFactory<LsEntry>(factory);
csf.setSessionWaitTimeout(1000);
csf.setPoolSize(10);
csf.setTestSession(true);
return csf;
}
我已经在其中一项服务中配置了所有这些。
现在的问题是,
有时整个操作需要超过 15 分钟~ 特别是如果服务是理想的几个小时,我不确定是什么导致了这个问题。看起来它正在花费时间从 CachedSessionFactory 获取活动会话,下面的操作非常快是我设法捕获时间的工具之一的快照。
传输文件通常需要几毫秒。
我最近做了以下更改,但在此之前我也遇到了同样的问题,
- 我之前已将 isShareSession 设置为 false,它是 DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
- 没有池大小我已将其设置为 10
我想我配置错误,这就是为什么我最终打桩连接?还是有别的东西?
观察:
完成操作所花费的时间在问题发生时都有些相似,即 938000 毫秒 +
如果我每天重新启动应用程序,它工作得很好。
解决方案
推荐阅读
- azure - 我们可以自定义或更改 APIM 的路由方法吗?
- python-3.x - 我需要帮助修复此列表的索引错误,请
- c# - 在没有配置 C# 的情况下从控制器中的 appsettings 访问 JSON 数组
- mysql - 如何使用柴油和 mysql 调用/部署无服务器功能?
- python - 使用 __add__ 方法相加
- php - 如何使用 .htaccess 页面创建简单的删除 .php 扩展名?
- php - 调用未定义的方法 Maatwebsite\\Excel\\Excel::selectSheetsByIndex()
- excel - Range 的删除方法失败
- bash - 在读取期间删除 bash 中的当前行
- python-3.x - 如何使用一个“for循环”从视图中渲染图像、标题和到模板的链接