cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting a message into multiple messages.

Former Member
0 Kudos

All,

I will simplify the issue we have and explain.

We have the following structure. (the occurence <data> node is unbounded)

<source>

<data>...</data>

<data>...</data>

<data>...</data>

</source>

we need to split this into another message <source2> with the exact same structure... but we need only 10 <data> nodes in the <source2>. In this <source2> the <data> node is of max occurs 10.

so if we get a <source> message with 1000 <data> nodes comes in, we need to split it into 100 <source2> messages.

How can we do this? (due to constraints we cannot use the file content conversion)

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Hi,

We can do it easily. Create UDF , in UDF take all the values in Queues. Run the loop, for every 10 counts add the values in the queue, then change the context,

I hope this will solve ur issue:

for(int i=0;i<Input_Values.length;i++)

{

if(i%10 ==0 and i ! =0)

result.addContextChange();

else

result.addValue(""Input_Values<i>"");

}

Best regards,

raj.

Former Member
0 Kudos

Raj,

And how will this UDF be used in the mapping? (i mean between which nodes.)

Here are the sample source and target structure. (for the sake of explaining easily - i will show the split for every 2 <data> nodes.

<source>

<data><name>j</name><desc>some desc</desc></data>

<data><name>j2</name><desc>some desc2</desc></data>

<data><name>j3</name><desc>some desc3</desc></data>

<data><name>j4</name><desc>some desc4</desc></data>

</source>

<sourceIdx>

<data><index>1</index><name>j</name><desc>some desc</desc></data>

<data><index>2</index><name>j2</name><desc>some desc2</desc></data>

</sourceIdx>

<sourceIdx>

<data><index>3</index><name>j3</name><desc>some desc3</desc></data>

<data><index>4</index><name>j4</name><desc>some desc4</desc></data>

</sourceIdx>

Thanks!

justin_santhanam
Active Contributor
0 Kudos

Hello,

Please check whether the below logic suits your scenario.

Change Messages - http://flickr.com/photo_zoom.gne?id=1064675286&size=o

Mapping -http://flickr.com/photo_zoom.gne?id=1064675070&size=o

Mapping -http://flickr.com/photo_zoom.gne?id=1064675164&size=o

UDF's- http://flickr.com/photo_zoom.gne?id=1064675480&size=o

Results http://flickr.com/photo_zoom.gne?id=1064675320&size=o (Source 4 Data)

Results http://flickr.com/photo_zoom.gne?id=1064675430&size=o (Source 5 Data)

The above example will split source data into 2 messages each.

If it doesn't helps, let me know.

Best regards,

raj.

Former Member
0 Kudos

Raj,

Thanks for the detailed replies. Appreciate your expertise and help!

Thanks.

justin_santhanam
Active Contributor
0 Kudos

U welcome buddy .!!!

Best regards,

raj.

Former Member
0 Kudos

Thanx for the detail explanation....

I appritiates ur way of presentation....

Keep going....:)

justin_santhanam
Active Contributor
0 Kudos

Thanks Harsha. The support from you guys make me to learn more!!! The solution which i'm suggesting might be to tedious inspite of easier solution avaiable. Anyhow I'll try to crack the easiest way and suggest the solutions henceforth.

Thanks for the support and encouragement!!!

Best regards,

raj.

Answers (3)

Answers (3)

Former Member
0 Kudos

thezone, are you trying to split the root element of this? If you are, you will need to use a bpm.

Former Member
0 Kudos

Hi,

The only way I can think of doing that is to create a context User Defined Function which takes in all data elements, which will come in as an array, and then create the output which will have a context change after each group of 10.

Here's a basic outline:

for (int ind = 0; ind < a.length; ind++)

{

if (ind % 10 == 0)

result.addValue(ResultList.CC);

result.addValue(a[ind]);

}

Yaghya

Former Member
0 Kudos

What are your adapters in this scenario?