I am using spring integration to setup a message flow. I read files from a directory, and do some stuff to them. I have setup a poller on my inbound-channel-adapter, that includes a transaction manager, and synchronization factory. The synchronization factory pushes after-commit and after-rollback to channels, which push the original file to either a success, or failure folder. This all works fine.
Now the issue, while processing some files, they may spawn new messages which I would like to loop through the same process. I do not want these new files being involved in the transaction of the original file, but I do want them to have their own transactional context.
I have tried to skin this cat multiple ways to get it to work. The closest I have gotten is to create a new message, and use a gateway to push to the starting channel (via an async call in order to terminate the transaction) - however because the transaction definition is on the file inbound-channel-adapter, the new messages do not get transactional support, so whether they pass or fail, they do not get pushed to the appropriate folder.
Is this the correct architecture, or is there a pattern I do not know about which i should use?
(p.s. the reason I do not just write the new files to the original directory that the adapter is polling, is that I want to include a header with them which points to the parent file. Therefore I have to create a message).
Any thoughts would be appreciated.