I'm quite new to Spring Integration and am having some difficulties with the following issue:
I have several files stored in my DB. I have functionality that allows users to specify one or more of these files to export to a particular SFTP location.
The functionality takes each specified file, say TEST1 and TEST2, and sends two Message
s for each file:
- message 1 contains the content of the file and is named TEST1_CONTENT
- message 2 contains an empty file (0 bytes) with name TEST1_EMPTY
Similarly for TEST2.
The problem is that TEST1_EMPTY arrives at the destination before TEST1_CONTENT (presumably because it is a lighter file). I need to ensure that the CONTENT file arrives before the EMPTY file. If, say, there are 100 files being processed from the DB (TEST1, TEST2, ..., TEST100), it is ok for TEST100_EMPTY to arrive before TEST53_CONTENT, so long as TEST53_EMPTY arrives after TEST53_CONTENT (and of course TEST100_CONTENT arrives before TEST100_EMPTY).
My code:
I have a @MessagingGateway
interface MyGateway
with one method - send()
.
I have a configuration class MyChannelConfig
with annotations:
@Configuration
@EnableIntegration
@IntegrationComponentScan(basePackageClasses = MyGateway.class)
It has one method - flow()
that returns an IntegrationFlow
:
return IntegrationFlows
.from("test")
.enrichHeaders(blah)
.transform(myTransformer) //this converts an object that represents my file to a Resource
.handle(myHandler) //this is where the TEST1_CONTENT and TEST1_EMPTY get created and returned as a Collection of Messages
.route(myRouter) //contains a method with the @Router annotation
.get();
More about MyHandler
:
It contains a @ServiceActivator
method that calls a method processResource
in class ResourceProcessor
. processResource
returns the Collection
(a List
) of Message
s.
Is there any way to ensure that the TESTX_EMPTY file isn't sent until the TESTX_CONTENT file arrives at its SFTP destination?