I have a Camel FTP route that has, in the body, a list of objects which I need to break up into multiple separate FTP transmissions with different FTP filenames.
I am thinking this should be a Splitter EIP pattern, however, I am not sure how to go about enabling the multiple separate FTP transmissions.
Example ...assuming I have 4 records in the Exchange ${body} which I wish to organize into 2 separate ftp transmissions, I can see how I could use code in a Process class to separate the body into 2 groups of records, however, the issue is how to then make this two separate FTP transmissions.
I have thought of bundling the different groups of records into separate Header or Property objects ( in the Process class ) but the issue is still the same ...how to subsequently process these Headers or Properties as two separate FTP transmissions.
I am considering using a approach but I get the feeling there is a more elegant way using the pattern.
I should note that I do not know in advance how many different groups of records ( and thus how many separate FTP transmissions & filenames ) I shall need ...in my example above there are 2, however, in reality there could could be many more.
Any thoughts or examples ?
By way of example ...lets assume following Process class to setup a sample Camel body:
class SetTestBody implements Processor {
@Override
void process(Exchange exchange) throws Exception {
final String body = exchange.getIn().getBody(String.class)
/**
attribute6 is the -key- to use as the FTP filename ... all sttribute6 occurences of same value go
to same ftp filename ...in example below, we would have 4 separate FTP file transfers ...
one for the 2 entries having 2041,
one for 6 entries having 2143,
one for 2 entries having 2106
*/
def r1 = [
[ 'sku':'ALLO' , 'attribute3':'72','attribute4':'Local991','attribute5':'RosRen', 'attribute6':'2041' ],
[ 'sku':'ALL2' , 'attribute3':'73','attribute4':'Local9910','attribute5':'RosRen', 'attribute6':'2143' ],
[ 'sku':'ALL5O' , 'attribute3':'74','attribute4':'Local9911','attribute5':'RosRen', 'attribute6':'2143' ],
[ 'sku':'ALL6O' , 'attribute3':'75','attribute4':'Local9912','attribute5':'RosRen', 'attribute6':'2143' ],
[ 'sku':'ALL7O' , 'attribute3':'76','attribute4':'Local9913','attribute5':'RosRen', 'attribute6':'2143' ],
[ 'sku':'ALL8O' , 'attribute3':'77','attribute4':'Local9914','attribute5':'RosRen', 'attribute6':'2041' ],
[ 'sku':'ALL9O' , 'attribute3':'78','attribute4':'Local9915','attribute5':'RosRen', 'attribute6':'2106' ],
[ 'sku':'ALL10O' , 'attribute3':'79','attribute4':'Local9916','attribute5':'RosRen','attribute6':'2143' ],
[ 'sku':'ALL1O1' , 'attribute3':'80','attribute4':'Local9917','attribute5':'RosRen','attribute6':'2143' ],
[ 'sku':'ALL1O2' , 'attribute3':'81','attribute4':'Local9918','attribute5':'RosRen','attribute6':'2106' ]
]
// Sort the list so all entries are in proper sorted order ( sorted on attribute6 )
def sortedBody = r1.sort{ a,b -> a['attribute6'] <=> b['attribute6']}
exchange.getIn().setBody(sortedBody);
}
}
Lets assume a sample route as follows:
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="rod-setTestBody-bean">
<from uri="timer://fetchData?repeatCount=1"/>
<log message="\n1 body is : ${body}\n"/>
<process id="process1" ref="setTestBody"/>
<log message="\n2 body is : ${body}\n"/>
<split>
<simple>${body}</simple>
<log message="\nBody after split is : ${body}\n"/>
<!--
I would like to send all records of same attribute6 value to a same ftp destination ...just with different filename
...all records for 2041 in 1 ftp transmission, all for 2106 in second ftp transmission, all for 2143 in third ftp transmission
-->
<to uri="mock:ftpDestination1"/>
</split>
</route>
</routes>