Part B - Message Splitting
In this lab you will add a Split component, to split a multiple-instance message into separate messages and process them individually. | |
---|---|
- Open the blueprint.xml file under Camel Context.
Create a new route in the same project
Routes Menu -> Add Route
- Add a File component from the Components palette to the new empty route.
Click on the Properties tab and enter the following values:
Advanced->Path -> Directory Name: MultipleInput
Consumer->Delete: True
Add a Split component from the Routing palette:
Edit Split properties:
Language: xpath
Expression: //stocktrading
Add a link between the File component and Split component.
Add a Log component from the Components palette, next to Split.
Message: Processing element: ${body}
Add a SetHeader component next to Log.
headerName: CamelFileName
- language: simple
expression: ${date:now:yyyyMMddhhmmssSSS}-read.xml
Add a File endpoint next to setHeader.
Advanced -> Path -> Directory Name:InputDir
Create a link between Split and Log.
- Create a link between Log and setHeader.
- Create a link between setHeader and File.
- Save the file (Ctrl+S).
- Inspect the contents of ~/FuseWorkshop/support/Lab3/File3.xml.
For each element in the XML document, the splitter will generate a new Message, which will be processed by the subsequent nodes in the route. If we set the “parallelProcessing” option to true in the splitter component, all the splitted messages would be processed concurrently. | |
---|---|
- Run the routes by right-clicking blueprint.xml -> Run As -> Local Camel Context (without tests)
- Right-click on the automatically created “MultipleInput” folder in the Project Explorer.
- Select Import -> File System.
- Browse to ~/FuseWorkshop/support/Lab3/ ,select File3.xml and click Finish.
- This should fire route #2, which will generate a file for each element in the incoming XML file.
- Then, each generated file (in the InputDir folder) should trigger an instance of route#1 to process it.
- Close all open files.
- Stop the camel routes by clicking the stop button.