gpt4 book ai didi

java - 如何将 replyChannel 设为 false 或 null?

转载 作者:行者123 更新时间:2023-11-30 10:14:30 28 4
gpt4 key购买 nike

我正在尝试在 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 的回复不感兴趣。

https://docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/messaging-channels-section.html#channel-special-channels

https://docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/configuration.html#annotations_on_beans

关于java - 如何将 replyChannel 设为 false 或 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50877869/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com