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

标签 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 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/

相关文章:

java - 是否可以让 ObjectProvider 提供来自其他包的对象?

java - Junit 在应用服务器外测试 JNDI InitialContext

java - 将方法发布为 Web 服务

java - 使用 Jackson 序列化 vertx JsonObject

java - 如何使用 jpa 规范向子查询添加和构建动态谓词?

spring - 使用 Spring Cloud Starter 和 Fabric8 时刷新不起作用

java - Log4j 具有不同记录器和一个属性文件的多个类

java - LinkedMultiValueMap SpringFramework 不迭代(错误 : cannot be cast to class)

java - react excel 文件下载损坏

spring-boot - Spring Boot 应用程序未在 CloudFoundry 中启动