Spring 集成 DSL SFTP 良好实践
Spring Integration DSL SFTP good practices
我目前正在尝试使用 SI DSL SFTP 功能推送一些文件。
我对这个 fwk 的使用不是很流利,所以我想知道是否有更好的方法来实现我想要实现的目标。
大致是这样的,除了复制文件的时候,其余的调用都处于超时状态...
奖金:是否有一些关于 SI DSL 的好读物(书籍或在线)?
(cafe si 样品和参考除外..)
编辑:
- 此 SI 流程是否遵循 SI 良好做法?
- 尽管文件已正确复制到 sftp 服务器,但为什么我的休息呼叫以超时结束?
Java 配置:
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class IntegrationConfig {
//flow gateway
@MessagingGateway
public interface FlowGateway {
@Gateway(requestChannel = "SftpFlow.input")
Collection<String> flow(Collection<File> name);
}
//sftp flow bean
@Bean
public IntegrationFlow SftpFlow() {
return f -> f
.split()
.handle(Sftp.outboundAdapter(this.sftpSessionFactory(), FileExistsMode.REPLACE)
.useTemporaryFileName(false)
.remoteDirectory(sftpFolder));
}
//sftp session config
@Bean
public DefaultSftpSessionFactory sftpSessionFactory() {
System.out.println("Create session");
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(sftpHost);
factory.setPort(Integer.valueOf(sftpPort));
factory.setUser(sftpUser);
factory.setPassword(sftpPwd);
factory.setAllowUnknownKeys(true);
return factory;
}
}
一个 RestController class :
@Autowired
private FlowGateway flowGateway;
@RequestMapping("/testSftp")
public String testSftp() {
flowGateway.flow(Arrays.asList(file1, file2, file3);
}
Spring 集成 Java DSL 完全基于 Spring 集成核心。因此,所有概念、方法、文档、示例等也都适用于此。
问题是什么?让我猜猜:"why does it timeout and blocks?" 这对我来说很明显,因为我知道在哪里阅读,但对其他人来说可能不清楚。下次请更具体一点:SO 上有足够多的人可以将您的问题关闭为 "Unclear".
那么,让我们分析一下您拥有的东西以及为什么它不是您想要的。
Spring 集成中的端点可以是 one-way
(Sftp.outboundAdapter()
) 或 request-reply
(Sftp.outboundGateway()
)。当 one-way
没有什么可以 return 并继续流程或发送回复时,这并不奇怪,就像您的情况一样。
我确定您对回复不感兴趣,否则您使用了不同的端点。
在从 .split()
发送所有项目后,该过程恰好停止,并且没有任何内容可发送回 @Gateway
,正如您的代码所暗示的那样:
Collection<String> flow(Collection<File> name);
具有非void
return 类型需要来自 requestChannel
.
下游流的 reply
有关详细信息,请参阅 Messaging Gateway。
也考虑使用
.channel(c -> c.executor(taskExecutor()))
在 .split()
之后将您的文件并行发送到 SFTP。
P.S。我不确定您还需要阅读什么,因为到目前为止,您的代码中的一切都很好,只有这个令人讨厌的 reply
问题。
我目前正在尝试使用 SI DSL SFTP 功能推送一些文件。
我对这个 fwk 的使用不是很流利,所以我想知道是否有更好的方法来实现我想要实现的目标。
大致是这样的,除了复制文件的时候,其余的调用都处于超时状态...
奖金:是否有一些关于 SI DSL 的好读物(书籍或在线)? (cafe si 样品和参考除外..)
编辑:
- 此 SI 流程是否遵循 SI 良好做法?
- 尽管文件已正确复制到 sftp 服务器,但为什么我的休息呼叫以超时结束?
Java 配置:
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class IntegrationConfig {
//flow gateway
@MessagingGateway
public interface FlowGateway {
@Gateway(requestChannel = "SftpFlow.input")
Collection<String> flow(Collection<File> name);
}
//sftp flow bean
@Bean
public IntegrationFlow SftpFlow() {
return f -> f
.split()
.handle(Sftp.outboundAdapter(this.sftpSessionFactory(), FileExistsMode.REPLACE)
.useTemporaryFileName(false)
.remoteDirectory(sftpFolder));
}
//sftp session config
@Bean
public DefaultSftpSessionFactory sftpSessionFactory() {
System.out.println("Create session");
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(sftpHost);
factory.setPort(Integer.valueOf(sftpPort));
factory.setUser(sftpUser);
factory.setPassword(sftpPwd);
factory.setAllowUnknownKeys(true);
return factory;
}
}
一个 RestController class :
@Autowired
private FlowGateway flowGateway;
@RequestMapping("/testSftp")
public String testSftp() {
flowGateway.flow(Arrays.asList(file1, file2, file3);
}
Spring 集成 Java DSL 完全基于 Spring 集成核心。因此,所有概念、方法、文档、示例等也都适用于此。
问题是什么?让我猜猜:"why does it timeout and blocks?" 这对我来说很明显,因为我知道在哪里阅读,但对其他人来说可能不清楚。下次请更具体一点:SO 上有足够多的人可以将您的问题关闭为 "Unclear".
那么,让我们分析一下您拥有的东西以及为什么它不是您想要的。
Spring 集成中的端点可以是 one-way
(Sftp.outboundAdapter()
) 或 request-reply
(Sftp.outboundGateway()
)。当 one-way
没有什么可以 return 并继续流程或发送回复时,这并不奇怪,就像您的情况一样。
我确定您对回复不感兴趣,否则您使用了不同的端点。
在从 .split()
发送所有项目后,该过程恰好停止,并且没有任何内容可发送回 @Gateway
,正如您的代码所暗示的那样:
Collection<String> flow(Collection<File> name);
具有非void
return 类型需要来自 requestChannel
.
reply
有关详细信息,请参阅 Messaging Gateway。
也考虑使用
.channel(c -> c.executor(taskExecutor()))
在 .split()
之后将您的文件并行发送到 SFTP。
P.S。我不确定您还需要阅读什么,因为到目前为止,您的代码中的一切都很好,只有这个令人讨厌的 reply
问题。