【发布时间】:2019-10-08 07:49:16
【问题描述】:
我正在尝试使用 SftpOutboundGateway 获取文件名列表。到目前为止,我已经尝试使用 Service Activator 注释和 IntegrationFlow Bean 创建 SftpOutboundGateway bean。两种解决方案都没有返回任何东西,除了日志;/。
网关接口
@MessagingGateway
public interface SftpCommandGateway {
@Gateway(requestChannel = "lsChannel")
List<String> lsRemote(@Payload String path);
}
调用 lsRemote 的服务
@Service
public class SftpInboundDefaultServiceImpl implements SftpInboundService {
private SftpCommandGateway sftpCommandGateway;
@Autowired
public SftpInboundDefaultServiceImpl(SftpCommandGateway sftpCommandGateway) {
this.sftpCommandGateway = sftpCommandGateway;
}
@Override
public List<String> availableFilenames() {
return sftpCommandGateway.lsRemote("'sftpTest/'");
}
}
配置文件:
@Configuration
@EnableIntegration
@IntegrationComponentScan("com.company.package")
public class SftpCommandConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(SftpCommandConfiguration.class);
private SessionFactory sessionFactory;
@Autowired
public SftpCommandConfiguration(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
// Secound approche with IntegrationFlow
// @Bean
// public IntegrationFlow lsIntegrationFlow() {
// return IntegrationFlows
// .from("lsChannel")
// .handle(Sftp.outboundGateway(sessionFactory, AbstractRemoteFileOutboundGateway.Command.NLST, "payload"))
// .log("info")
// .get();
// }
@Bean
@ServiceActivator(inputChannel = "lsChannel")
public SftpOutboundGateway lsHandler() {
SftpOutboundGateway gateway = buildSftpOutboundGateway("nlst");
gateway.setOption(AbstractRemoteFileOutboundGateway.Option.NOSORT);
gateway.setOutputChannelName("lsResults");
return gateway;
}
private SftpOutboundGateway buildSftpOutboundGateway(String command) {
SftpOutboundGateway gateway = new SftpOutboundGateway(sessionFactory,
command, "payload");
gateway.setLoggingEnabled(true);
return gateway;
}
}
我希望收到文件名列表,但现在事件不会返回“availableFilenames()”
控制台日志中的其他内容我可以看到:
bean 和服务激活器示例
o.s.integration.channel.DirectChannel : preSend on channel 'lsChannel', message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, id=a5bd6c88-edbd-4f78-e521-aabf62827571, timestamp=1570521590725}]
2019-10-08 09:59:50.726 DEBUG 11880 --- [nio-8080-exec-6] o.s.i.sftp.gateway.SftpOutboundGateway : lsHandler received message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, id=a5bd6c88-edbd-4f78-e521-aabf62827571, timestamp=1570521590725}]
集成流示例
2019-10-08 09:21:03.430 DEBUG 15056 --- [nio-8080-exec-4] o.s.integration.channel.DirectChannel : preSend on channel 'lsChannel', message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, id=9cc72ea7-152f-7a40-011a-90f56b7abdad, timestamp=1570519263430}]
2019-10-08 09:21:03.432 DEBUG 15056 --- [nio-8080-exec-4] o.s.i.sftp.gateway.SftpOutboundGateway : lsIntegrationFlow.org.springframework.integration.sftp.gateway.SftpOutboundGateway#0 received message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, id=9cc72ea7-152f-7a40-011a-90f56b7abdad, timestamp=1570519263430}]
你能告诉我我做错了什么或缺少什么吗?
【问题讨论】:
标签: spring-integration spring-integration-sftp