[英]How to configure spring-integration-sftp to move a remote file after it has been downloaded to local filesystem?
[英]Spring Integration: delete (sftp) remote file after it has been persisted to database
(有關上下文,請參閱我之前的問題)
仍在努力從 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 --- [scheduling-1] osintegration.handler.LoggingHandler: org.springframework.messaging.MessageHandlingException: 消息處理程序 [ServiceActivator for [org.springframework.integration.handler .MethodInvokingMessageProcessor@3be14a03] (Sftp2DB.remove.serviceActivator)]; 嵌套異常是 org.springframework.messaging.core.DestinationResolutionException:沒有可用的輸出通道或回復通道 header,failedMessage=GenericMessage [payload=org.springframework.integration.jpa.outbound.JpaOutboundGateway@6a0e79fb,headers={id=788f63b5-ad62 -de6b-bbb1-ecde94d23576,時間戳=1669290613815}]
有兩種類型的@ServiceActivator
(和@Transformer
等)。
定義消息處理程序的 POJO 方法(如您的轉換器)和 bean。
您的服務激活器需要定義為@Bean
s(就像您對入站通道適配器所做的那樣)。
請參閱https://docs.spring.io/spring-integration/docs/current/reference/html/configuration.html#annotations和https://docs.spring.io/spring-integration/docs/current/reference/html /configuration.html#annotations_on_beans
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.