Blog 6: Splitting messages in Integration Flows
Hello Integrators!
In this blog, we shall look into the splitter pattern provided in SAP Cloud Platform Integration. The use of a splitter is quite clear from its name – to break out a composite message into a series of individual messages, each containing data related to one item.
How is Splitter supported in Integration Flows?
In SAP Cloud Platform Integration, a splitter is available as a Message Routing flowstep. When you configure a splitter flowstep, it can appear confusing at first. Lots of options!
Nevertheless, let us try to understand Iterating and General Splitter first.
A very cool way to understand the workings of the splitter is by configuring a integration flow like below (idea courtesy: HCI development team).
In the Content Modifier step, I insert the following payload in the Body. It is group of orders:
Each order has details in the following format.
Now, let us see how the splitter works. In the first splitter, after the content modifier, we have configured a General splitter the following properties.
The exclusive gateway step routes the message according to the ordernumber.
Let us go to the second splitter that has been configured as a Iterating splitter with expression type as Token.
This is how the output of the second splitter looks like. Notice that the root tags of the incoming payload is not retained and further, it has been grouped as per the number provided.
Note: The Token splitter is mainly used for non-xml payload. I have just illustrated this example so that you can understand its working. Here “<item>” (including the angle brackets) form the “token”.
And if we configure the Iterating splitter with the expression type as XPath and the properties as below, we get the same output as the previous one. The only difference being there shall be the XML tag in the beginning of the output message <?xml version=”1.0″ encoding=”UTF-8″?>.
The forth splitter is also a General splitter. But, I recommend that you configure the same so that you can see the difference with the Iterating splitter against the same message. The difference lies in the enveloping signature of the XML. Compare this output with the previous one.
Conclusion
You use the splitter flow step in SAP Cloud Platform Integration to break down a composite message. For XML payloads, you would use the general and iterative-xpath splitters. Iterative-token type is used for non-xml payloads. The other variants – IDOC and PKCS are used in specific scenarios. I shall cover those in another blog.
Best Regards,
Sujit
Hi Sujit, These series of blogs about dev in HCI are very very very useful. I am your big fan. Thanks a lot for sharing. Br Misher
Thanks for your kind words, Misher!
Hi Sujit,
I have a similar requirement like you showed. In the end, instead of generating separate output documents I want to combine in a single document. It is like I am executing in a loop i.e. one employee at a time based on their employee status and then I want to send a single document in the end. As employees are being executed 1 at a time therefore n number of documents are being created currently.
What I understand is that we cannot use Gather after router so please help me with best possible solution.
Thanks,
Arpna
Hi Arpna,
Not sure if it's relevant still, but for the benefit of others:
You simply put the part where you do the routing into a subprocess.
Note that if you want to discard records with routing, then this is not possible in a subprocess, since all records that go to an end event will be returned to the calling process. For this, you use a filter instead.
Hi Casper!
Thanks for the great article.
I have a situation similar to what Arpna described, the only difference being, I don't want to gather all the data from individual 'splits' into a single document.
If I place a splitter and right after it I add a router, can I end each 'route' in its own individual 'end message' event?
Another way of saying this is- is it okay if the payload splits into 1000 branches and each branch chooses a 'route' (based on some condition), and terminates within the route without ever consolidating with the other branches?
(I should also point out that each 'route' needs to perform its own specific API calls. This will result in 1000 API calls for the 1000 branches coming from the splitter. Is this the right way to do it, or is there a better approach?)
Thanks for reading, I'd appreciate any help I can get!
-Ashish
Hi Arpna,
I have same requirement like yours. Have you got any solutions about this scenario?
Thanks and best regards
Eric
Hi Sujit,
When we use Iterating splitter, do we get to know the index of the item that we are iterating currently in the flow?
Is there any index variable set by HCI so that we can use it?
Thanks & Regards,
Poornapragna
${property.CamelSplitIndex}
Check this
Hi Sujit ,
Thanks for your sharing.
is that grouping field support to parameterized?
Thanks ,
Chris
Hi Sujit
Im trying to use the inverse condition. I have a requirement to check if the data exists after payload gather. While I insert a Router element after gather, I'm getting a type conversion exception with [#document:null] Not sure what to do to have the data check after gather.
I have explained my problem in the following link.
https://answers.sap.com/questions/12664528/exception-while-using-router-after-gather-cpi.html
Regards, Aanand.
Hi All,
But when we use the General Splitter, the nodes which are in next element to the configured element are not resulting in the output. Example below.
If we configure the Xpath to split on job_information, the compensation_information and PaymentInformationV3 is not coming out from the output of GeneralSplitter.
I read in SAP blog that this is the functionality of General Splitter, which is not useful anymore as we need to map the target with compensation_information and PaymentInformationV3 nodes as well.
Kindly suggest what can be done? Shall we ask SAP to introduce a splitter that can acheive the functionality that we are expecting?