Reputation: 13
I have requirement to read the files from the source directory and process it sequentially (one by one).
I have below application context configuration,
<?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>
As per above configuration, file inbound adapter will get one file per poll and execute the service executor.
But meanwhile if the system is getting another file then the file inbound adapter should not trigger the service again until the first transaction is finished.
Please let me know the way to handle this issue with some samples.
Upvotes: 1
Views: 688
Reputation: 174739
Remove the <queue/>
from adapterInputChanel
and remove the <poller/>
from the service activator.
Then, the channel will be a DirectChannel
and your service will run on the adapter's poller thread and the next file won't be processed until the service exits.
You can read about different channel types here; specifically the difference between subscribable and pollable channels.
Upvotes: 0