如何将 replyChannel 设为 false 或 null?
How to replyChannel in false or null?
我正在尝试在 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']");
}
你需要这样配置:
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(...);
sftpOutboundGateway.setOutputChannelName("nullChannel");
return sftpOutboundGateway;
如果您对 SftpOutboundGateway
的回复不感兴趣。
我正在尝试在 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']");
}
你需要这样配置:
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(...);
sftpOutboundGateway.setOutputChannelName("nullChannel");
return sftpOutboundGateway;
如果您对 SftpOutboundGateway
的回复不感兴趣。