Java 如何在false或null中回复频道?

Java 如何在false或null中回复频道?,java,spring,spring-boot,spring-integration,spring-integration-sftp,Java,Spring,Spring Boot,Spring Integration,Spring Integration Sftp,我正在尝试删除SFTP中的文件,我正在使用SftpOutboundGateway,所有功能都正常,文件在SFTP中删除,但删除后,发送异常: MessageHandlingException: error occurred in message handler [handler]; nested exception is org.springframework.messaging.core.DestinationResolutionException: no output-channel or

我正在尝试删除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.
如何省略无输出通道或应答通道

@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']");
    }
@配置
公共类集成配置{
//…属性
私有静态记录器Logger=LogManager.getLogger();;
@豆子
LocalDateTime currentLocalDateTime(){
返回LocalDateTime.now();
}
/**
*会话工厂
*
*@return SessionFactory
*/
@豆子
公共会话工厂sftpSessionFactory(){
DefaultSftpSessionFactory=新的DefaultSftpSessionFactory();
工厂设置主机(sftpHost);
系统输出打印LN(sftpHost);
工厂设置端口(sftpPort);
工厂设置用户(sftpUser);
如果(sftprivateKey!=null){
出厂设置私钥(SFTPrivateKey);
factory.setPrivateKeyPassphrase(SFTPrivateKeyPassphrase);
}否则{
出厂设置密码(sftpassword);
}
工厂。setAllowUnknownKeys(真);
返回新的CachingSessionFactory(工厂);
}
@豆子
公共SftpRemoteFileTemplate模板(){
返回新的SftpRemoteFileTemplate(sftpSessionFactory());
}
@豆子
@InboundChannelAdapter(channel=“sftStream”,poller=@poller(maxMessagesPerPoll=“5”,cron=“0-55 9**?”)///fixedDelay=“50000”
public MessageSource ftpMessageSource(){
SftpStreamingMessageSource messageSource=新的SftpStreamingMessageSource(模板());
setRemoteDirectory(sftpRemoteDirectory);
info(“文件过滤器:”+FileListFilter);
logger.info(“范围日期:“+rangeDate”);
messageSource.setFilter(新的SftpSimplePatternFileListFilter(FileListFilter));//*.ack
messageSource.setFileInfoJson(false);
messageSource.setMaxFetchSize(5);
返回消息源;
}
/**
*过滤消息文件
* 
*@param消息
*@返回
*/
@过滤器(inputChannel=“sftStream”,outputChannel=“deleteSftpFile”,discardChannel=“filterDiscardFile”)
公共布尔过滤器FTPFILE(消息){
布尔过滤器=假;
SftpFileInfo SftpFileInfo=(SftpFileInfo)message.getHeaders().get(“file_remoteFileInfo”);
logger.info(消息);
LocalDateTime sftpFiledate=LocalDateTime.ofInstant(Instant.ofEpochMilli(sftpFileInfo.getModified()),
ZoneId.systemDefault());
if(比较sftpFiledate(sftpFiledate)){
logger.info(“文件将被删除”+sftpFileInfo.getRemoteDirectory()+sftpFileInfo.getFilename());
过滤器=真;
}
回流过滤器;
}
/**
*丢弃文件。
* 
*@param sftpFileInfo
*/
@ServiceActivator(inputChannel=“filterDiscardFile”)
public void handlediscardefile(@Header(“file_remoteFileInfo”)SftpFileInfo SftpFileInfo){
logger.info(“filterSFTPFile()接收到消息并将其丢弃:”+sftpFileInfo.getRemoteDirectory()
+sftpFileInfo.getFilename());
}
/**
*发送消息删除SFTP中的文件
* 
*@返回
*/
@豆子
@ServiceActivator(inputChannel=“deleteSftpFile”)
public MessageHandler(){
返回新的SftpOutboundGateway(sftpSessionFactory(),“rm”,
“标题['file\u remoteDirectory']+标题['file\u remoteFile']”;
}

您需要如下配置:

SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(...);
sftpOutboundGateway.setOutputChannelName("nullChannel");
return sftpOutboundGateway;
如果您对来自
SftpOutboundGateway
的回复不感兴趣