Before an order goes to picking, every line is checked against the stock service over HTTP. The stock service runs inside this same example, so there is nothing else to start: the first two routes are a trimmed copy of stock-api, the third is the client.
INFO ... http-client.camel.yaml:112 : ORD-1001: CAMEL-TSHIRT x 2, 120 in stock, ok INFO ... http-client.camel.yaml:112 : ORD-1001: CAMEL-MUG x 1, 42 in stock, ok INFO ... http-client.camel.yaml:112 : ORD-1002: CAMEL-MUG x 3, 42 in stock, ok INFO ... http-client.camel.yaml:112 : ORD-1003: CAMEL-TSHIRT x 1, 120 in stock, ok INFO ... http-client.camel.yaml:116 : ORD-1003: CAMEL-CAP x 1, only 0 in stock, back-order INFO ... http-client.camel.yaml:112 : ORD-1003: CAMEL-MUG x 2, 42 in stock, ok
Install JBang and the Camel CLI as described in the root README; camel --version confirms the install.
camel run *
The three orders in orders/ are read once each (noop: true leaves the files in place), so the run can be repeated. The stock levels are in stock.json.
order-lines does, and calls toD with http://localhost:8080/stock/${variable.sku}: toD because the URI is built per message.sku would collide with the {sku} path parameter on the server side. Variables stay in the route.throwExceptionOnFailure=false turns a 404 into a normal response with CamelHttpResponseCode set, so the choice can log it instead of the error handler.stock-api and add a file route on orders that logs each order.http://localhost:8080/stock/CAMEL-MUG with a fixed SKU; log the response body.toD and a variable; notice the body is gone after the call.throwExceptionOnFailure=false and the choice on the response code and the quantity.throwExceptionOnFailure=false and add a SKU that does not exist to an order: the 404 becomes an HttpOperationFailedException handled by the error handler.https://api.github.com/repos/apache/camel for example, and log ${body[stargazers_count]}.camel.server.port to another port and update the URI to match.The example comes with a test in the Citrus YAML DSL, test/http-client.citrus.it.yaml, which the Camel CLI runs:
camel test run test/http-client.citrus.it.yaml
The test starts the routes and verifies the ok and back-order lines.
If you hit any problem using Camel or have some feedback, then please let us know.
We also love contributors, so get involved :-)
The Camel riders!