Reputation: 13471
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?
Upvotes: 1
Views: 1782
Reputation: 174554
For even more flexibility, SI 2.2 introduced the ability to add behavior to endpoints via an advice mechanism, One standard advice provided is the ExpressionEvaluatingRequestHandlerAdvice which allows you to take different actions based on whether the (e.g. service activator) call succeeds or fails...
The associated sample app shows, for example, how to rename a file after a failure to send over FTP, or delete it if the FTP operation succeeds.
Upvotes: 1
Reputation: 13471
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.
Upvotes: 2
Reputation: 21000
Use a wiretap before the service activator to copy the message and send it to another channel.
Upvotes: 0