我正在尝试删除SFTP中的文件,我正在使用SftpOutboundGateway
,所有功能都没问题,该文件在SFTP中被删除但是当它被删除时,发送一个异常:
MessageHandlingException: error occurred in message handler [handler]; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available.
如何省略no output-channel or replyChannel
?
@Configuration
public class IntegrationConfiguration {
//...properties
private static Logger logger = LogManager.getLogger();;
@Bean
LocalDateTime currentLocalDateTime() {
return LocalDateTime.now();
}
/**
* SFTP Session Factory
*
* @return SessionFactory
*/
@Bean
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
factory.setHost(sftpHost);
System.out.println(sftpHost);
factory.setPort(sftpPort);
factory.setUser(sftpUser);
if (sftpPrivateKey != null) {
factory.setPrivateKey(sftpPrivateKey);
factory.setPrivateKeyPassphrase(sftpPrivateKeyPassphrase);
} else {
factory.setPassword(sftpPassword);
}
factory.setAllowUnknownKeys(true);
return new CachingSessionFactory<LsEntry>(factory);
}
@Bean
public SftpRemoteFileTemplate template() {
return new SftpRemoteFileTemplate(sftpSessionFactory());
}
@Bean
@InboundChannelAdapter(channel = "sftStream", poller = @Poller(maxMessagesPerPoll = "5", cron="0 0-55 9 * * ?")) //fixedDelay = "50000"
public MessageSource<InputStream> ftpMessageSource() {
SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template());
messageSource.setRemoteDirectory(sftpRemoteDirectory);
logger.info("File filter: " + fileListeFilter);
logger.info("Range Date: " + rangeDate);
messageSource.setFilter(new SftpSimplePatternFileListFilter(fileListeFilter)); //*.ack
messageSource.setFileInfoJson(false);
messageSource.setMaxFetchSize(5);
return messageSource;
}
/**
* Filter message File
*
* @param message
* @return
*/
@Filter(inputChannel = "sftStream", outputChannel = "deleteSftpFile", discardChannel = "filterDiscardFile")
public boolean filterSFTPFile(Message<?> message) {
boolean filter = false;
SftpFileInfo sftpFileInfo = (SftpFileInfo) message.getHeaders().get("file_remoteFileInfo");
logger.info(message);
LocalDateTime sftpFiledate = LocalDateTime.ofInstant(Instant.ofEpochMilli(sftpFileInfo.getModified()),
ZoneId.systemDefault());
if (compareSftpFileDate(sftpFiledate)) {
logger.info("File will be deledted " + sftpFileInfo.getRemoteDirectory() + sftpFileInfo.getFilename());
filter = true;
}
return filter;
}
/**
* Discard file.
*
* @param sftpFileInfo
*/
@ServiceActivator(inputChannel = "filterDiscardFile")
public void handleDiscardedFile(@Header("file_remoteFileInfo") SftpFileInfo sftpFileInfo) {
logger.info("Message is received and it was discarded by filterSFTPFile(): " + sftpFileInfo.getRemoteDirectory()
+ sftpFileInfo.getFilename());
}
/**
* Send message to delete file in SFTP
*
* @return
*/
@Bean
@ServiceActivator(inputChannel = "deleteSftpFile")
public MessageHandler handler() {
return new SftpOutboundGateway(sftpSessionFactory(), "rm",
"headers['file_remoteDirectory'] + headers['file_remoteFile']");
}
答案 0 :(得分:1)
您需要像这样配置:
df['dates'] = df['time'].dt.date
如果您对SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(...);
sftpOutboundGateway.setOutputChannelName("nullChannel");
return sftpOutboundGateway;
的回复不感兴趣。