Spring integration Spring集成:使用公共根多线程创建sftp目录失败
我有多个线程通过Spring integration Spring集成:使用公共根多线程创建sftp目录失败,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我有多个线程通过sftp.outboundAdapter上传sftp文件。每个线程都需要创建一个具有公共根的目录路径。我得到一个异常,它告诉我公共根存在: org.springframework.messaging.MessageDeliveryException: Failed to transfer file ... Caused by: org.springframework.core.NestedIOException: failed to create remote directory
sftp.outboundAdapter
上传sftp文件。每个线程都需要创建一个具有公共根的目录路径。我得到一个异常,它告诉我公共根存在:
org.springframework.messaging.MessageDeliveryException: Failed to transfer file
...
Caused by: org.springframework.core.NestedIOException: failed to create remote directory '/my/import/de3fb731-6a56-11e9-bfd2-0242ac140022'.; nested exception is 4: Eine Datei kann nicht erstellt werden, wenn sie bereits vorhanden ist.
at org.springframework.integration.sftp.session.SftpSession.mkdir(SftpSession.java:232)
at org.springframework.integration.file.remote.RemoteFileUtils.makeDirectories(RemoteFileUtils.java:71)
at org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:545)
at org.springframework.integration.file.remote.RemoteFileTemplate.doSend(RemoteFileTemplate.java:337)
... 150 common frames omitted
Caused by: com.jcraft.jsch.SftpException: Eine Datei kann nicht erstellt werden, wenn sie bereits vorhanden ist.
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp.mkdir(ChannelSftp.java:2182)
at org.springframework.integration.sftp.session.SftpSession.mkdir(SftpSession.java:229)
... 153 common frames omitted
我猜RemoteFileUtils#makeDirectories
在决定创建路径时存在竞争条件。两个线程都确定需要创建路径段,但当两个线程都尝试创建路径段时,第二个线程失败
一个可能的解决方法是提前创建公共路径,但这很笨拙,因为Sftp.outboundGateway
中没有这样的命令,似乎我必须上载带有autoCreateDirectories
的虚拟文件,然后删除虚拟文件
有没有更好的办法解决这个问题?向sftp出站网关添加mkdirs命令有意义吗?当autoCreateDirectories
为true时,是否应该有一个忽略现有目录错误的标志
一种可能的解决方法是提前创建公共路径,但这很笨拙,因为Sftp.outboundGateway中没有这样的命令
您可以在初始化期间自己调用RemoteFileUtils.makeDirectories
(通过SftpRemoteFileTemplate.execute(会话->…)
)获取会话)
但是,我同意实用程序应该捕获并忽略该异常。请打开一张支票
欢迎投稿。。