本文介绍了Spring Integration +文件读取消息源_入站通道适配器+出站网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For File reading message source Inbound Adapter and transformer with annotations is configured as below

@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 {

}

现在,我想更改变形金刚"以引用出站网关的答复通道,即将文件从一个目录移动到另一个目录,即将文件从入站通道目录移动到另一个目录,然后进行处理或转换文件或执行一些验证

Now I want to change the Transformer to refer to a reply channel of outbound gateway i.e. which moves the files from one directory to another directory i.e. move the file from incomingchannel directory to a different directory and the process or transform he file or perform some validations

<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配置转换为注释配置或任何想法吗?

Anyone has converted above XML configuration to annotation configurations or any ideas?

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

After annotation configurations I will have to change the transformer input channel to refer to newdirectory channel i.e. which is a reply channel of messaging gateway...

在此先感谢您的任何帮助或建议

Thanks in advance for any help ot suggestions regarding this

---试用Artem链接中提供的代码段

--- Update 1 after trying out the snippet provided in link by Artem

@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. 入站适配器试图将目录也作为文件进行轮询(使用了递归目录扫描程序)-如何确保未将目录作为文件进行轮询

  1. Inbound Adapter is trying to poll the directory also as file (Recursive Directory scanner is used) - How to ensure that directory is not polled as a file

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

推荐答案

好.由于看起来您想将FileWritingMessageHandler放在@InboundChannelAdapter之后和@Transformer之前,所以应该这样:

Ok. Since it looks like you would like to place the FileWritingMessageHandler after @InboundChannelAdapter and before @Transformer, so this should like:

@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 {

}

通过这种方式,@InboundChannelAdapter将文件发送到FileWritingMessageHandler进行逻辑处理,从而为下一个流@Transformer生成结果文件,以将结果文件转换为JobLaunchRequest.而且只有在此之后,消息才会被发送到jobLaunchChannel以提交Spring Batch Job.

This way an @InboundChannelAdapter sends a File into a FileWritingMessageHandler for its logic, which produces a result file for the next in flow @Transformer to convert a result file into a JobLaunchRequest. And only after that a message is going to be sent to the jobLaunchChannel to file a Spring Batch Job.

这篇关于Spring Integration +文件读取消息源_入站通道适配器+出站网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:33