【问题标题】:Spring Integration: delete (sftp) remote file after it has been persisted to databaseSpring Integration:将远程文件持久化到数据库后删除(sftp)
【发布时间】:2022-11-28 23:36:02
【问题描述】:

(有关上下文,请参阅我的previous question

仍在努力从 SFTP 服务器获取文件,将其内容保存到数据库,然后删除该文件,如果它一直没有错误。我可以正确处理处理程序、网关和流程。

我需要指导,请

我有的:


@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 错误 948 --- [调度-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:没有可用的输出通道或 replyChannel 标头,failedMessage=GenericMessage [payload=org.springframework.integration.jpa.outbound.JpaOutboundGateway@6a0e79fb,headers={id=788f63b5-ad62 -de6b-bbb1-ecde94d23576,时间戳=1669290613815}]

【问题讨论】:

    标签: java spring spring-integration spring-integration-sftp


    【解决方案1】:

    有两种类型的@ServiceActivator(和@Transformer等)。

    定义消息处理程序的 POJO 方法(如您的转换器)和 bean。

    您的服务激活器需要定义为 @Bean s(就像您对入站通道适配器所做的那样)。

    参见https://docs.spring.io/spring-integration/docs/current/reference/html/configuration.html#annotationshttps://docs.spring.io/spring-integration/docs/current/reference/html/configuration.html#annotations_on_beans

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      相关资源
      最近更新 更多