You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Integration:持久化SFTP文件到数据库后删除远程文件遇错求助

SFTP文件入库后删除远程文件的实现问题

我正在实现从SFTP服务器获取文件、将内容持久化到数据库,且仅在持久化无错误时删除远程文件的功能,但始终无法正确处理handler、gateway和flow,特此寻求指导。

以下是我的代码:

@Configuration
@EnableIntegration
class Sftp2DB {

    @Bean
    @InboundChannelAdapter(channel = "transform")
    public MessageSource<InputStream> source() {
        return Sftp
            .inboundStreamingAdapter(template(this.sessionFactory))
            .remoteDirectory("inbound")
            .get();
    }

    @Transformer(inputChannel="transform", outputChannel = "persist")
    public Message<MyEntity> transform(final Message<InputStream> in) throws IOException {
        var entity = new MyEntity();
        entity.setContent(in.getPayload().readAllBytes());
        entity.setFilename(in.getHeaders().get(FileHeaders.FILENAME, String.class));
        return MessageBuilder.withPayload(entity).build();
    }

    @ServiceActivator(inputChannel = "persist", outputChannel = "remove")
    public JpaOutboundGateway persist() {
        return Jpa
            .updatingGateway(this.entityManager)
            .entityClass(MyEntity.class)
            .persistMode(PersistMode.PERSIST)
            .get();
    }

    @ServiceActivator(inputChannel = "remove")
    public AbstractRemoteFileOutboundGateway<LsEntry> remove() {
        return Sftp
            .outboundGateway(
                this.sessionFactory,
                "rm", 
                String.format("header['%s'] + '/' + header['%s']", FileHeaders.REMOTE_DIRECTORY, FileHeaders.REMOTE_FILE)
            )
            .get();
            
    }
}

运行后出现如下错误:

2022-11-24 12:50:13.815 ERROR 948 --- [ scheduling-1] o.s.integration.handler.LoggingHandler : org.springframework.messaging.MessageHandlingException: 消息处理器[ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@3be14a03] (Sftp2DB.remove.serviceActivator)]处理出错;嵌套异常为org.springframework.messaging.core.DestinationResolutionException: 无可用的output-channel或replyChannel头信息,failedMessage=GenericMessage [payload=org.springframework.integration.jpa.outbound.JpaOutboundGateway@6a0e79fb, headers={id=788f63b5-ad62-de6b-bbb1-ecde94d23576, timestamp=1669290613815}]

内容的提问来源于stack exchange,提问作者Christoph Dahlen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 18:25:23