|
Page Edited :
CAMEL :
Tutorial-Trading-Partners
Tutorial-Trading-Partners has been edited by Aaron Mulder (Sep 13, 2008). Content:
Background and IntroductionSo there's a company, which we'll call Acme. Acme sells widgets, in a fairly unusual way. Their customers have stock rooms with tons of Acme widgets, owned by Acme. When the customer requires a widget, they take it out of the stock room. Then they enter into their own systems (ERP or whatever) that they bought the widget. Then at some point, their systems emit a record of the sale which needs to go to Acme so Acme can bill them for it. Obviously, everyone wants this to be as automated as possible, so there needs to be integration between the customer's system and Acme. Sadly, Acme's sales people are, technically speaking, doormats. They tell all their prospects, "you can send us the data in whatever format, using whatever protocols, whatever. You just can't change once it's up and running." The result is pretty much what you'd expect. Taking a random sample of 3 customers:
Now on the Acme side, all this has to be converted to a canonical XML format and submitted to the Acme accounting system via JMS. Then the Acme accounting system sends an XML reply via JMS, with a summary of what it processed (e.g. 3 line items accepted, line item #2 in error, total invoice $123.45). Finally, that data needs to be formatted into an e-mail, and sent to a contact at the customer in question ("Dear Joyce, we received an invoice on 1/2/08. We accepted 3 line items totaling $123.45, though there was an error with line items #2 [invalid quantity ordered]. Thank you for your business. Love, Acme."). So it turns out Camel can handle all this:
This tutorial will cover all that, plus setting up tests along the way. High-Level DiagramHere's more or less what the integration process looks like. First, the input from the customers to Acme: And then, the output from Acme to the customers: Tutorial TasksHere's what we'll try to accomplish in this tutorial:
Let's Get Started!Step 1: Initial Maven buildWe'll use Maven for this project as there will eventually be quite a few dependencies and it's nice to have Maven handle them for us. You should have a current version of Maven (e.g. 2.0.9) installed. You can start with a pretty empty project directory and a Maven POM file, or use a simple JAR archetype to create one. Here's a sample POM. We've added a dependency on camel-core, and set the compile version to 1.5 (so we can use annotations): pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"> <modelVersion>4.0.0</modelVersion> <groupId>org.apache.camel.tutorial</groupId> <artifactId>trading-partners</artifactId> <version>1.0</version> <name>Camel Trading Partners Tutorial</name> <dependencies> <dependency> <artifactId>camel-core</artifactId> <groupId>org.apache.camel</groupId> <version>1.4.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> </plugins> </build> </project>
If you look at these files, you'll see that the different input formats use different field names and/or ordering, because of course the sales guys were totally OK with that. Sigh. Step 3: XSD and JAXB Beans for the Canonical XML FormatHere's the sample of the canonical XML file: <?xml version="1.0" encoding="UTF-8"?> <invoice xmlns="http://activemq.apache.org/camel/tutorial/partners/invoice"> <partner-id>2</partner-id> <date-received>9/12/2008</date-received> <line-item> <product-id>134</product-id> <description>A widget</description> <quantity>3</quantity> <item-price>10.45</item-price> <order-date>6/5/2008</order-date> </line-item> <!-- // more line-item elements here --> <order-total>218.82</order-total> </invoice> If you're ambitions, you can write your own XSD (XML Schema) for files that look like this. If not, you can download mine Generating JAXB BeansDown the road we'll want to deal with the XML as Java POJOs. We'll take a moment now to set up those XML binding POJOs. So we'll update the Maven POM to generate JAXB beans from the XSD file. We need a dependency: <dependency> <artifactId>camel-jaxb</artifactId> <groupId>org.apache.camel</groupId> <version>1.4.0</version> </dependency> And a plugin configured: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxb2-maven-plugin</artifactId> <executions> <execution> <goals> <goal>xjc</goal> </goals> </execution> </executions> </plugin> That should do it (it automatically looks for XML Schemas in src/main/xsd to generate beans for). Run mvn install and it should emit the beans into target/generated-sources/jaxb. Initial Work on Customer 1 Input (XML over FTP)Create an XSLT templateCreate a unit testInitial Work on Customer 2 Input (CSV over HTTP)Create a CSV-handling POJOCreate a unit testInitial Work on Customer 3 Input (Excel over e-mail)Create an Excel-handling POJOCreate a unit testPut this all together into Camel routes for the Customer InputCreate a unit test for the Customer Input Routes |
Unsubscribe or edit your notifications preferences
