My 3rd Camel Ride
Christina Lin
Different VIP status file needs to be handled differently, so it's time to introduce our "Enterprise Integration Patterns" - Content-Based Router.
Subtitle
-
File Endpoint
-
uri: file://myxml?delete=true
-
-
Log Endpoint
-
Message: ${in.header.CamelFileName} with content -> ${body}
-
-
Data Transformation
-
Transform ID: transOrder
-
Dozer file path: transOrder.xml
-
Source Type: XML
-
Target Type: Java
- XML Type Definition: XML Schema
- Source File: xsdfiles/stocktrading.xsd/
- Target class: org.blogdemo.example.TradOrder
-
Remove links between Data Transformations & log
- Choice
- When
- language: simple
- expression ${body.vip} >= 3
- When
DON NOT SAVE YET!!!!!!!!
- Choice
- When
- language: simple
- SetHeader
- headerName: CamelFileName
- language: simple
- expression: ${date:now:yyyyMMddhhmmss}-read.json
- When
-
- Link setHeader to log node
And then Save
-
Choice
-
setHeader
- headerName: CamelFileName
- language: simple
- expression: ${date:now:yyyyMMddhhmmss}-read.json
-
log
- message: ${body.name} has brought Stock ${body.stockId} with shares ${body.shares}
-
marshal (json)
- Unmarshal Type Name: org.blogdemo.example.TradeOrder
- Library: Jackson
- PrettyPrint: true
-
log
- message: JSON ${body}
-
file
- Directory Name:donejson
-
setHeader
- Otherwise
- SetHeader
- headerName: CamelFileName
- language: simple
- expression: ${date:now:yyyyMMddhhmmss}-read.xml
- SetHeader
Move existing node, please remove the links to/from
the setHeader node
Move the setHeader node right after otherwise node and link them together
- Otherwise
-
- Convert
- type: java.lang.String
- File Endpoint
- uri: file://donejson
- Convert
Another vendor comes alone, but they prefer to combine all their order in a XML file. Add a new route to the Camel Context to accommodate the changes without affecting the old one.
- File Endpoint
- Directory Name: otherVendor
- delete: true
- Spilt Tag
- language: tokenize
- xml: true
- token: stocktrading
- <tokenize xml="true" token="stocktrading" />
Save the route after done dragging splitter to canvas
Go to source, and replace the spliter tokenize tag
A pop-up will appear, with warning, click ok
- Log Endpoint
- Message: Multiple ${body}
- SetHeader
- headerName: CamelFileName
- language: simple
- expression: ${date:now:yyyyMMddhhmmssSSS}-read.xml
- File Endpoint
- Directory Name: myxml
Run the application and put the new xml file in the otherVendor directory
APPENDIX - order01.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<stocktrading>
<name>Christina Lin</name>
<custId>A123456789</custId>
<vip>1</vip>
<stockId>XYZ</stockId>
<shares>11</shares>
</stocktrading>
APPENDIX - order02.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<stocktrading>
<name>Frank Jarrod</name>
<custId>F475678678</custId>
<vip>4</vip>
<stockId>ABC</stockId>
<shares>20</shares>
</stocktrading>
APPENDIX - order03.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Red Hat Stock Exchange and Trading Systems-->
<multiple>
<stocktrading>
<name>John Osborn</name>
<custId>K34567854</custId>
<vip>1</vip>
<stockId>KUJ</stockId>
<shares>25</shares>
</stocktrading>
<stocktrading>
<name>Sarah Fox</name>
<custId>C3456767878</custId>
<vip>5</vip>
<stockId>SOU</stockId>
<shares>10</shares>
</stocktrading>
</multiple>
3rd Camel Ride completed!
My 3rd Camel Ride
By weimeilin
My 3rd Camel Ride
- 8,909