hpandalai
hpandalai

Reputation: 458

Message Splitter

I needed to split a message into 3 different payloads and transform and send to 3 routers. So the payload initially will have a header a body or detail and a footer. These 3 different payloads need to be extracted and send to 3 different routers. What would be the most efficient way to do it.

Upvotes: 0

Views: 716

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

It depends on your body/payload type. If your payload is XML, you can easily split it using xpath and route it using content based routing similar to:

<splitter expression="#[xpath('//nodes/node)']" />
        <choice>
            <when expression="#[xpath('//node/id').text ='myid']">
                <!-- Route somewhere -->
            </when>
            <otherwise>
                <!-- Route somewhere else -->
            </otherwise>
        </choice>

The expression splitter above can take any MEL expression to split up your payload. There are many other splitters, for example if your payload is already a java Collection, you can simply use the collection-splitter.

Other splitter info can be found here: http://www.mulesoft.org/documentation-3.2/display/32X/Message+Splitting+and+Aggregation

Also there are other routers that can help you with fork and join patterns if you need to process messages asynchronously as well. Here's a good post on that: http://java.dzone.com/articles/aggregation-mule-%E2%80%93-%E2%80%9Cfork-and

Upvotes: 1

Related Questions