【发布时间】: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