I would like to proccess all the files located in a specific folder using <int-file:inbound-channel-adapter>
and only after having tranformed/moved all files that have beed retrieved in a single poll make a call to the database to update a table.
Can this be done using and Aggregator
. Is it possible to know filenames count in advance. In order to configure a release strategy.
Is there another option ?
Yes. This really looks like a task for an aggregator if you need to know all those files information for updating database.
It is indeed not possible to know the number of file to make the standard
RealeaseStrategy
happy for some specific number.I would suggest to have some static correlation key and
expireGroupsUponCompletion = true
to be able to form a new group on subsequent directory polls when new files are appeared. You need to be sure that you don't do thread shifting with your process and have poller configured for afixed-delay
. This way a new poll request won't happen until the current is done.To make everything work in the end I suggest to look into
ReceiveMessageAdvice
and implement itsafterReceive()
the way that you check for aMessage<?> result
if it isnull
which means no more files to emit as messages from the<int-file:inbound-channel-adapter>
. Thisnull
could be a signal for your<aggregator>
to release the group. So, you just send some marker message to an aggregator input channel from thisafterReceive()
and some customRealeaseStrategy
on that aggregator would check if this marker message is present in the group to returntrue
for its contract.You may then somehow filter out that marker message downstream from an aggregator result before updating the database.
See more info about
ReceiveMessageAdvice
in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/polling-consumer.html#smart-polling