如何使用Spring集成文件入站适配器按顺序处理文件
我需要从源目录中读取文件并按顺序(一个接一个)处理它 我有以下应用程序上下文配置如何使用Spring集成文件入站适配器按顺序处理文件,spring,spring-integration,Spring,Spring Integration,我需要从源目录中读取文件并按顺序(一个接一个)处理它 我有以下应用程序上下文配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/sc
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:file="http://www.springframework.org/schema/integration/file"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<int:channel id="controlChannel" />
<int:channel id="adapterInputChanel">
<int:queue />
</int:channel>
<int:control-bus input-channel="controlChannel" />
<file:inbound-channel-adapter id="inboundAdapter"
directory="inputdir"
channel="adapterInputChanel" auto-startup="false" prevent-duplicates="true"
ignore-hidden="true">
<int:poller id="poller" fixed-delay="5000"
max-messages-per-poll="1">
</int:poller>
</file:inbound-channel-adapter>
<int:service-activator input-channel="adapterInputChanel"
ref="mainService" method="readFiles" output-channel="filesOut">
<int:poller fixed-delay="500" />
</int:service-activator>
<bean id="mainService" class="com.sample.MainService">
</bean>
<file:outbound-channel-adapter id="filesOut"
directory="output dir" />
</beans>
根据上述配置,文件入站适配器将在每次轮询中获得一个文件,并执行服务执行器
但同时,如果系统正在获取另一个文件,则文件入站适配器在第一个事务完成之前不应再次触发服务
请通过一些示例告诉我处理此问题的方法。从适配器计算机通道中删除
,并从维修激活器中删除
然后,该通道将是一个DirectChannel
,您的服务将在适配器的轮询器线程上运行,并且在服务退出之前不会处理下一个文件
你可以读到;特别是可订阅和可轮询频道之间的差异。谢谢。成功了。我正在使用控制总线启动/停止这些轮询过程,如下所示,controlChannel=ac.getBean(“controlChannel”,MessageChannel.class);SubscribableChannel adapterInputChanel=ac.getBean(“adapterInputChanel”,SubscribableChannel.class);发送(新的GenericMessage(“@inboundAdapter.start()”);但问题是,如果停止适配器,相应的服务将立即终止。在这种情况下,文件入站适配器应该只停止进一步的轮询。你能告诉我这一点吗?停止适配器不会影响当前线程,除非它做了一些可中断的事情。如果是,您可以使用延迟停止-使用控制总线向轮询器发送消息,告诉它在轮询返回null
(或在下一次轮询之前,取决于您的要求)时停止适配器。