Search code examples
javaspringmessagingspring-integration

Spring Integration - Forward Original Message and Reply After Processing


I've got some instances where I want a Spring Integration component (a service activator) to take in a message with a File payload, and produce some output. Additionally, once the component has produced this output, I'd like to pass the original File message on to a different channel.

The use case is I've got some files coming in, being sent to two parallel processing streams (archive to S3, and parse contents). Thanks to Gary Russel I've used the publish-subscribe channel's apply-sequence="true" behaviour on the original File message. When both streams have finished with a file they should put the File message with the original correlation headers onto a 'processed' channel, from where an Aggregator groups them, and when both have been aggregated puts them on a channel that feeds a service activator that deletes the files.

So, in summary, I want a service activator to put its output on one channel, and at the same time put the original message it received on to another channel.

UPDATE

Would I be better off using publish-subscribe synchronously with the subscribers being executed serially in the order specified by the order attribute?


Solution

  • I used a publish-subscribe channel without a task-executor specified, and then put an order property on each subscriber.

    The first subscriber does its thing, and emits its own different output (parsed file contents in my case); I made the subsequent parts of this asynchronous by using an ExecutorChannel downstream of it.

    The second subscriber doesn't execute until the first has finished, and gets the same input message (in this case the file). I made the second subscriber a Bridge that pushed the File to the channel that would lead to the "things I'm finished with" processing pipeline ready to be deleted.