Spring集成+文件读取消息源_Inbound Channel Adapter + Outbound Gateway
Spring Integration + file reading message source _ Inbound Channel Adapter + Outbound Gateway
用于文件读取消息源入站适配器和转换器
带有注释的配置如下
@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 {
}
现在我想更改 Transformer 以引用出站网关的回复通道,即将文件从一个目录移动到另一个目录,即将文件从 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
在 link 中提供的片段后更新 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);
}
但是遇到了两个问题
入站适配器正尝试将目录也作为文件轮询(使用递归目录扫描器)- 如何确保目录不作为文件轮询
嵌套异常是 org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available, failedMessage=GenericMessage [payload=C
好的。因为看起来你想把 FileWritingMessageHandler
放在 @InboundChannelAdapter
之后和 @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 {
}
通过这种方式,@InboundChannelAdapter
将文件发送到 FileWritingMessageHandler
中用于其逻辑,从而为下一个流程生成结果文件 @Transformer
以将结果文件转换为 JobLaunchRequest
。只有在那之后,一条消息才会被发送到 jobLaunchChannel
以提交 Spring 批处理 Job
.
用于文件读取消息源入站适配器和转换器 带有注释的配置如下
@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 {
}
现在我想更改 Transformer 以引用出站网关的回复通道,即将文件从一个目录移动到另一个目录,即将文件从 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
在 link 中提供的片段后更新 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);
}
但是遇到了两个问题
入站适配器正尝试将目录也作为文件轮询(使用递归目录扫描器)- 如何确保目录不作为文件轮询
嵌套异常是
org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available, failedMessage=GenericMessage [payload=C
好的。因为看起来你想把 FileWritingMessageHandler
放在 @InboundChannelAdapter
之后和 @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 {
}
通过这种方式,@InboundChannelAdapter
将文件发送到 FileWritingMessageHandler
中用于其逻辑,从而为下一个流程生成结果文件 @Transformer
以将结果文件转换为 JobLaunchRequest
。只有在那之后,一条消息才会被发送到 jobLaunchChannel
以提交 Spring 批处理 Job
.