Composed Message Processor

Camel supports the Composed Message Processor from the EIP patterns book.

How can you maintain the overall message flow when processing a message consisting of multiple elements, each of which may require different processing?


Use Composed Message Processor to process a composite message. The Composed Message Processor splits the message up, routes the sub-messages to the appropriate destinations and re-aggregates the responses back into a single message.

With Camel, this pattern is implemented by the Splitter which has built-in aggregation to re-aggregate the responses back into a single message.


This example uses the Split EIP as composed message processor to process each split message, aggregate and return a single combined response.

The route and the code comments below explain how you can use the Split EIP to split each message to sub-message which are processed individually and then combined back into a single response message via the custom AggregationStrategy (MyOrderStrategy), as the output from the Split EIP.

// this routes starts from the direct:start endpoint
// the body is then split based on @ separator
// the splitter in Camel supports InOut as well, and for that we need
// to be able to aggregate what response we need to send back, so we provide our
// own strategy with the class MyOrderStrategy.
    .split(body().tokenize("@"), new MyOrderStrategy())
        // each split message is then send to this bean where we can process it
        // this is important to end the splitter route as we do not want to do more routing
        // on each split message
    // after we have split and handled each message, we want to send a single combined
    // response back to the original caller, so we let this bean build it for us
    // this bean will receive the result of the aggregate strategy: MyOrderStrategy

More details

See the Splitter EIP.