I have the usecase to read employee, address and contact files in parallel and convert that to beanIO object and merge the beanIO object to produce the complete employeeDetails object.
Emp File:
1 Foo Engineer
2 Bar AssistantEngineer
Emp Contact File:
1 8912345678 foo@org.com
2 7812345678 bar@org.com
Emp Address File:
1 city1 1234
2 city2 2345
Expected output in a EmployeeDetailsBeanIODataFormat object in Exchange:
1 Foo Engineer foo@org.com city1 1234
2 Bar AssistantEngineer bar@org.com city2 2345
I have the following routes
from("file://C:/cameltest/employee.txt").to("seda:beanIO");
from("file://C:/cameltest/employeeContact.txt").to("seda:beanIOContact");
from("file://C:/cameltest/employeeAddress.txt").to("seda:beanIOAddress");
Each file is converted to beanio object
BeanIODataFormat empFormat = new BeanIODataFormat("beanIO.xml","emp");
BeanIODataFormat empContactFormat = new BeanIODataFormat("beanIO.xml", "empContact");
BeanIODataFormat empAddressFormat = new BeanIODataFormat("beanIO.xml", "empAddress");
from("seda:beanIO").unmarshal(empFormat).log("body - ${body}");
from("seda:beanIOContact").unmarshal(empContactFormat).log("Contact body ${body}");
from("seda:beanIO").unmarshal(empAddressFormat).log("Address body - ${body}");
The output logs the bean objects correctly.
Now I need to merge the objects to form EmployeeDetails object. Can someone let me know how to do this? I have read and it seems like Aggregators can be used to do this job, but not sure with the approach.
Any idea on this with sample will be helpful. Suggestions are welcome, is it advisable to merge the files first based on employee id and create an object out of it? I dont want to write the merged file into disk in this case as IO will cost the performance.
Thanks in Advance.
Use a splitter to split each message after the unmarshalling
And then here is how an aggregator could look like. The details object is stored as a header in the olddExchange. The most important parameters are the following
And
Then the outcome would be 2 details objects