0

对于文件读取消息源入站适配器和带注释的转换器配置如下

@Bean
@InboundChannelAdapter(autoStartup = "false", value = "incomingchannel", poller = @Poller("custompoller"))
    public MessageSource<File> fileReadingMessageSource() {

}

@Transformer(inputChannel = "incomingchannel", outputChannel = "jobLaunchChannel")
    public JobLaunchRequest toRequest(Message<File> message) throws Exception {

}

现在我想更改变压器以引用出站网关的回复通道,即将文件从一个目录移动到另一个目录,即将文件从incomingchannel目录移动到另一个目录,并处理或转换他的文件或执行一些验证

<file:outbound-gateway id="mover" request-channel="incomingchannel" reply-channel="newdirectory" directory="<<path to new directory file to be moved" delete-source-files="true"/>

有人将上述 XML 配置转换为注释配置或任何想法吗?

注释配置后,我将不得不更改转换器输入通道以引用新目录通道,即消息网关的回复通道...

在此先感谢您提供有关此问题的任何帮助或建议

--- 试用 Artem 链接中提供的片段后更新 1

@Bean
@ServiceActivator(inputChannel = "incomingchannel")
public MessageHandler fileWritingMessageHandler() {
    FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(newdirectorypath));
    handler.setFileExistsMode(FileExistsMode.APPEND);
    handler.setDeleteSourceFiles(true);
    return handler;
}

@MessagingGateway(defaultRequestChannel = "incomingchannel", defaultReplyChannel = "newdirectorychannel")
public interface MyGateway {

    void writeToFile(@Header(FileHeaders.FILENAME) String fileName, @Header(FileHeaders.FILENAME) File directory,
            String data);

}

但是遇到了两个问题

  1. 入站适配器正在尝试将目录也作为文件轮询(使用递归目录扫描器) - 如何确保不将目录作为文件轮询

  2. 嵌套异常是org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available, failedMessage=GenericMessage [payload=C

4

1 回答 1

0

好的。因为看起来你想放置FileWritingMessageHandlerafter@InboundChannelAdapter和 before @Transformer,所以这应该是:

@Bean
@InboundChannelAdapter(autoStartup = "false", value = "incomingchannel", poller = @Poller("custompoller"))
    public MessageSource<File> fileReadingMessageSource() {

}

@Bean
@ServiceActivator(inputChannel = "incomingchannel")
public MessageHandler fileWritingMessageHandler() {
    FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(newdirectorypath));
    handler.setFileExistsMode(FileExistsMode.APPEND);
    handler.setDeleteSourceFiles(true);
    handler.setOutputChannelName("jobLaunchTransfromerCannel");
    return handler;
}

@Transformer(inputChannel = "jobLaunchTransfromerCannel", outputChannel = "jobLaunchChannel")
    public JobLaunchRequest toRequest(Message<File> message) throws Exception {

}

这样,an@InboundChannelAdapter将 File 发送到 aFileWritingMessageHandler用于其逻辑,该逻辑为下一个流程生成结果文件,@Transformer以将结果文件转换为JobLaunchRequest. 只有在那之后,才会将消息发送jobLaunchChannel到归档 Spring Batch Job

于 2020-04-22T20:05:50.687 回答