[英]Spring Integration - file adapter
I'm newbie to Spring, I am writing a file adapter which reads file from the input folder and move the files to output folder. 我是Spring的新手,正在编写一个文件适配器,该适配器将从输入文件夹中读取文件并将文件移至输出文件夹。 I played with the following examples but there are some points that are not clear to me.
我玩了以下示例,但是有些地方我不清楚。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<file:inbound-channel-adapter id="filesIn"
directory="C:\Users\my\Desktop\files\in"
filename-regex="[a-z]+.txt">
<integration:poller id="poller" fixed-delay="5000"/>
</file:inbound-channel-adapter>
<file:file-to-string-transformer input-channel="filesIn" output-channel="strings"/>
<integration:channel id="strings"/>
<integration:service-activator input-channel="strings"
output-channel="filesOut"
ref="handler"/>
<file:outbound-channel-adapter id="filesOut" directory="C:\Users\my\Desktop\files\out"/>
<bean id="handler" class="org.springframework.integration.samples.filecopy.Handler"/>
I have few more questions regarding the above file. 关于以上文件,我还有其他几个问题。
<integration:channel id="strings"/>
tag. <integration:channel id="strings"/>
标记,我不清楚。 Why its just string. strings
. strings
使用的其他可能值是什么? input-channel
of the integration:service-activator
and output-channel
of the file-to-string-transformer
has nothing to do with <integration:channel id="strings"/>
is it correct? input-channel
的的integration:service-activator
和output-channel
的的file-to-string-transformer
无关与<integration:channel id="strings"/>
是它正确的吗? handler
bean which is used in integration:service-activator
has 3 methods. integration:service-activator
使用的handler
bean integration:service-activator
有3种方法。
public class Handler { public String handleString(String input) { System.out.println("Copying text: " + input); return input.toUpperCase(); } public File handleFile(File input) { System.out.println("Copying file: " + input.getAbsolutePath()); return input; } public byte[] handleBytes(byte[] input) { System.out.println("Copying " + input.length + " bytes ..."); return new String(input).toUpperCase().getBytes(); } }
And currently it fires only one method which is handleString(String whichTakesString)
is it because of the <integration:service-activator input-channel="strings"
? 并且当前它仅触发一个方法
handleString(String whichTakesString)
是因为<integration:service-activator input-channel="strings"
吗? How can I call the other methods, what is the way to do it. 我如何调用其他方法,该怎么做? I tried to figure this out many ways but still no chance.
我试图通过多种方法来解决这个问题,但仍然没有机会。
First of all it looks like you haven't got enough theoretical knowledges, so consider to read the books: EIP Book , Spring Integration in Action . 首先,您似乎还没有足够的理论知识,所以请考虑阅读以下书籍: EIP书籍 , Spring Integration in Action 。
In general MessageChannel
is a concept to carry messages between services via loosely-coupling manner. 通常,
MessageChannel
是通过松耦合方式在服务之间传递消息的概念。
strings
is just a bean name and it can be any value. strings
只是一个bean名称 ,它可以是任何值。 <integration:channel>
is just a custom tag, which produces a MessageChannel
in the end. <integration:channel>
只是一个自定义标记,它最终会产生一个MessageChannel
。 To be more comfortable with that you should to read the Reference Manual . 为了使自己更加满意,您应该阅读参考手册 。
Since you use <file:file-to-string-transformer>
, the result of this component will be String
file representation. 由于您使用
<file:file-to-string-transformer>
,因此此组件的结果将是String
文件表示形式。
Your <service-activator>
invokes handleString
method of your Handler
because the runtime payload
argument type resolution. 您的
<service-activator>
调用您的Handler
handleString
方法,因为运行时payload
参数类型解析。
To make it worked with other methods you should use appropriate transformer ( <file:file-to-bytes-transformer>
) or don't use it at all - the <file:inbound-channel-adapter>
produces File
object as payload
for resulting message. 为了使其与其他方法一起使用,您应该使用适当的转换器(
<file:file-to-bytes-transformer>
)或根本不使用它- <file:inbound-channel-adapter>
产生File
对象作为payload
用于结果消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.