You are on page 1of 7

FuseSource A Progress Software Company

Download New Camel IDE Today


Created by James Strachan, co-founder of Apache Camel

IDE for implementing enterprise integration patterns easily in ServiceMix using Camel

Go to fusesource.com/ide and try it out today

fusesource.com
Experts in professional open source integration & messaging
#47
Get More Refcardz! Visit refcardz.com

CONTENTS INCLUDE:
n
About Enterprise Integration Patterns The Top Twelve Integration Patterns
About Apache Camel
for Apache Camel
n

n
Essential Patterns
Conclusions and more...
By Claus Ibsen
n

r
Update fomel
c h e C a
Apa

Camel Camel supports Pipes and Filters using the pipeline node.
ABOUT ENTERPRISE INTEGRATION PATTERNS
Java DSL from(“jms:queue:order:in”).pipeline(“direct:transformOrd
er”, “direct:validateOrder”, “jms:queue:order:process”);

Integration is a complex problem. To help deal with the Where jms represents the JMS component used for consuming JMS
messages on the JMS broker. Direct is used for combining endpoints in a
complexity of integration problems, the Enterprise Integration synchronous fashion, allowing you to divide routes into sub routes and/or
Patterns (EIP) have become the standard way to describe, reuse common routes.

document and implement complex integration problems. Hohpe Tip: Pipeline is the default mode of operation when you specify multiple
outputs, so it can be omitted and replaced with the more common node:
& Woolf’s book the Enterprise Integration Patterns has become from(“jms:queue:order:in”).to(“direct:transformOrder”,
the bible in the integration space – essential reading for any “direct:validateOrder”, “jms:queue:order:process”);
integration professional. TIP: You can also separate each step as individual to nodes:
from(“jms:queue:order:in”)
Apache Camel is an open-source project for implementing .to(“direct:transformOrder”)
.to(“direct:validateOrder”)
the EIP easily in a few lines of Java code or Spring XML .to(“jms:queue:order:process”);
configuration. This Refcard guides you through the most XML DSL <route>
common Enterprise Integration Patterns and gives you examples <from uri=”jms:queue:order:in”/>
<pipeline>
of how to implement them either in Java code or using Spring <to uri=”direct:transformOrder”/>
XML. This Refcard is targeted at software developers and <to uri=”direct:validateOrder”/>
<to uri=”jms:queue:order:process”/>
enterprise architects, but anyone in the integration space can </pipeline>
</route>
benefit as well. <route>
<from uri=”jms:queue:order:in”/>
<to uri=”direct:transformOrder”/>
The Top Twelve Integration Patterns for Apache Camel

ABOUT APACHE CAMEL <to uri=”direct:validateOrder”/>


<to uri=”jms:queue:order:process”/>
</route>

Apache Camel is a powerful open-source integration platform Message Router


based on Enterprise Integration Patterns (EIP) with powerful Bean
How can you deouple individual processing steps so that messages can be
Integration. Camel lets you implement EIP routing using Camels passed to different filters depending on a set of conditions?
intuitive Domain Specific Language (DSL) based on Java (aka outQueue 1
fluent builder) or XML. Camel uses URI for endpoint resolution inQueue
so it’s very easy to work with any kind of transport such as HTTP,
outQueue 2
REST, JMS, web service, File, FTP, TCP, Mail, JBI, Bean (POJO)
Message Router
and many others. Camel also provides data formats for various
popular formats such as CSV, EDI, FIX, HL7, JAXB, Json, Xstream. Problem Pipes and Filters route each message in the same processing steps. How can
Camel is an integration API that can be embedded in any server we route messages differently?
of choice such as J2EE Server, ActiveMQ, Tomcat, OSGi, or Solution Filter using predicates to choose the right output destination.
as standalone. Camel’s Bean Integration let you define loose Camel Camel supports Message Router using the choice node. For more details see
coupling allowing you to fully separate your business logic from the Content-Based router pattern.
the integration logic. Camel is based on a modular architecture
allowing you to plug in your own component or data format, so
they seamlessly blend in with existing modules. Camel provides
a test kit for unit and integration testing with strong mock and
assertion capabilities.

ESSENTIAL PATTERNS
Ready to start development with Camel?
This group consists of the most essential patterns that anyone Come to FuseSource for
working with integration must know.
• IDE, Training & Consulting
Pipes and Filters
How can we perform complex processing on a message while maintaining • Getting started resources
independence and flexibility?
• Enterprise subscriptions
Pipe Pipe Pipe Pipe
Decrypt Authenticate De-Dup

Incoming Filter Filter Filter ‘Clean’


Order Order
Problem

Solution
A single event often triggers a sequence of processing steps.

Use Pipes and Filters to divide a larger processing steps (filters) that are
FuseSource Free downloads-fusesource.com
connected by channels (pipes).

DZone, Inc. | www.dzone.com


2 The Top Twelve Integration Patterns for Apache Camel

Content-Based Router Java DSL public class OrderTransformProcessor


implements Processor {
How do we handle a situation where the implementation of a single logical public void process(Exchange exchange)
function (e.g., inventory check) is spread across multiple physical systems? throws
Exception {
// do message translation here
Widget 
 }
Inventory 
}

from(“direct:transformOrder”)
Gadget .process(new OrderTransformProcessor());
New Order Router Inventory
Bean
Instead of the processor, we can use Bean (POJO). An advantage of using
Problem How do we ensure a Message is sent to the correct recipient based on
a Bean over Processor is the fact that we do not have to implement or use
information from its content?
any Camel specific interfaces or types. This allows you to fully decouple your
Solution Use a Content-Based Router to route each message to the correct recipient beans from Camel.
based on the message content. public class OrderTransformerBean {
Camel Camel has extensive support for Content-Based Routing. Camel supports public StringtransformOrder(String body) {
content based routing based on choice, filter, or any other expression. 
 // do message translation here

 }

Java DSL from(“jms:order.process”) }
.choice()
.when(header(“type”).isEqualTo(“widget”)) Object transformer = new OrderTransformerBean();
.to(“jms:order.widget”) from(“direct:transformOrder”).bean(transformer);
.when(header(“type”).isEqualTo(“gadget”))
.to(“jms:order.gadget”) TIP: Camel can create an instance of the bean automatically; you can just refer
.otherwise() to the class type.
.to(“jms:order.other”);
from(“direct:transformOrder”)
XML DSL <route> .bean(OrderTransformerBean.class);
<from uri=”jms:order.process”/>
<choice> TIP: Camel will try to figure out which method to invoke on the bean in case
<when> there are multiple methods. In case of ambiguity, you can specify which
<simple>${header.type} == ‘widget’</simple> methods to invoke by the method parameter:

<to uri=”jms:order.widget”/>
</when> from(“direct:transformOrder”)
<when> .bean(OrderTransformerBean.class, “transformOrder”);
<simple>${header.type} == ‘gadget’</simple>
<to uri=”jms:order.gadget”/> Transform
</when>
Transform is a particular processor allowing you to set a response to be
<otherwise>
returned to the original caller. We use transform to return a constant ACK
<to uri=”jms:order.other”/>
response to the TCP listener after we have copied the message to the JMS
</otherwise>
queue. Notice we use a constant to build an “ACK” string as response.
</choice>
</route>
from(“mina:tcp://localhost:8888?textline=true”)
.to(“jms:queue:order:in”)

TIP: In XML DSL you cannot invoke code, as opposed to the Java DSL. To .transform(constant(“ACK”));
express the predicates for the choices we need to use a language. We will use
simple language that uses a simple expression parser that supports a limited XML DSL Processor
set of operators. You can use any of the more powerful languages supported <route>
in Camel such as: JavaScript, Groovy, Unified EL and many others. <from uri=”direct:transformOrder”/>

<process ref=”transformer”/>

</route>
TIP: You can also use a method call to invoke a method on a bean to evaluate
the predicate. Lets try that: <bean id=”transformer” class=”com.mycompany.
<when> OrderTransformProcessor”/>
<method bean=”myBean” method=”isGadget”/>
... In XML DSL, Camel will look up the processor or POJO/Bean in the registry
</when> based on the id of the bean.
<bean id=”myBean” class=”com.mycomapany.MyBean”/>
Bean
<route>
public boolean isGadget(@Header(name = “type”) String
<from uri=”direct:transformOrder”/>
type) {
<bean ref=”transformer”/>

return type.equals(“Gadget”);
</route>
}
Notice how we use Bean Parameter Binding to instruct Camel to invoke this <bean id=”tramsformer”
method and pass in the type header as the String parameter. This allows your class=”com.mycompany.OrderTransformBean”/>
code to be fully decoupled from any Camel API so its easy to read, write and
unit test. Transform
<route>
<from uri=”mina:tcp://localhost:8888?textline=true”/>
Message Translator <to uri=”jms:queue:order:in”/>

<transform>
How can systems using different data formats communicate with each other <constant>ACK</constant>

using messaging? </transform>
</route>
Translator Annotation You can also use the @Consume annotation for transformations. For
DSL example, in the method below we consume from a JMS queue and do
the transformation in regular Java code. Notice that the input and output
parameters of the method is String. Camel will automatically coerce the
payload to the expected type defined by the method. Since this is a JMS
example, the response will be sent back to the JMS reply-to destination.
Incoming Message Translated Message
@Consume(uri=”jms:queue:order:transform”)

public String transformOrder(String body) {

 // do message translation
Problem Each application uses its own data format, so we need to translate the
}
message into the data format the application supports.

Solution Use a special filter, a message translator, between filters or applications to TIP: You can use Bean Parameter Binding to help Camel coerce the Message
translate one data format into another. into the method parameters. For instance, you can use @Body, @Headers
parameter annotations to bind parameters to the body and headers.
Camel Camel supports the message translator using the processor, bean or
transform nodes.

TIP: Camel routes the message as a chain of processor nodes.

DZone, Inc. | www.dzone.com


3 The Top Twelve Integration Patterns for Apache Camel

Message Filter Annotation Pay attention to the Camel route as you must invoke the bean as if it were a
DSL, regular bean instead.
How can a component avoid receiving unwanted messages? continued from(“jms:queue:order”)
.bean(new MyRouterBean());
TIP: You can use @Body, @Header, and @Headers annotations to bind
parameters to the message body and headers in the method signature of the
route method on the bean.

Widget Gadget Widget Message Widget Widget


Quote Quote Quote Filter Quote Quote Recipient List
Problem How do you discard unwanted messages? How do we route a message to a list of statically or dynamically specified
recipients?
Solution Use a special kind of Message Router, a Message Filter, to eliminate undesired
messages from a channel based on a set of criteria. Recipient Channel
Camel Camel has support for Message Filter using the filter method. The filter A
evaluates a predicate whether its true or false; only allowing the true condition
to pass the filter, where as the false condition will silently be ignored. B
Java DSL We want to discard any test messages so we only route non-test messages to
the order queue.
C
Recipient
from(“jms:inbox”) List D
.filter(header(“test”).isNotEqualTo(“true”))
.to(“jms:order”);
Problem How can we route messages based on a static or dynamic list of destinations?
XML DSL In the XML DSL we use the built-in expression language (simple) to define the
predicate to be used by the filter. Solution Define a channel for each recipient. Then use a Recipient List to inspect an
incoming message, determine the list of desired recipients and forward the
<route> message to all channels associated with the recipients in the list.
<from uri=”jms:inbox”/>
<filter> Camel Camel supports the static Recipient List using the multicast node, and the
<simple>${header.test} == false</simple> dynamic Recipient List using the recipientList node.
<to uri=”jms:order”/>
</filter> Java DSL Static
</route> In this route, we route to a static list of two recipients that will receive a copy of
the same message simultaneously.

Dynamic Router from(“jms:queue:inbox”)


.multicast().to(“file://backup”, “seda:inbox”);
How can you avoid the dependency of the router on all possible destinations
while maintaining its efficiency? Dynamic
In this route, we route to a dynamic list of recipients defined in the message
Dynamic Router Output Channel header [mails] containing a list of recipients as endpoint URLs. The bean
processMails is used to add the header[mails] to the message.
A
Message Router from(“seda:confirmMails”).beanRef(processMails)
Input Channel Output Channel .recipientList(“destinations”);
B And in the process mails bean we use @Headers Bean Parameter Binding to
Output Channel provide a java.util.Map to store the recipients.
public void confirm(@Headers Map headers, @Body String
C body} {

 String[] recipients = ...

 headers.put(“destinations”, recipients);

Dynamic }
Rule Base
XML DSL Static
Control Channel
<route>
Problem How can we route messages based on a dynamic list of destinations? <from uri=”jms:queue:inbox/>

<multicast>
Solution Use a Dynamic Router, a router that can self-configure based on special <to uri=”file://backup”/>

configuration messages from participating destinations. <to uri=”seda:inbox”/>
</multicast>
Camel Camel has support for Dynamic Router using the dynamicRouter method. </route>
An expression must be provided to determine where the message should be
routed next. After the message has been routed Camel will re-evaluate the Dynamic
expression to compute where the message should go next. It will keep doing In this example, we invoke a method call on a Bean to provide the dynamic
this until the expression returns null to indicate the end. list of recipients.
Java DSL We use a bean as the expression to compute where the message should be routed. <route>

<from uri=”jms:queue:inbox/>

public class MyRouter {
<recipientList>
public String whereToGo(String body) {
<method bean=”myDynamicRouter” method=”route”/>
// query a data store to find where we should go next.
</recipientList>
Return null to indicate end.
</route>
}
} <bean id=”myDynamicRouter”
We can then use the bean in the dynamicRouter in the Camel route: class=”com.mycompany.MyDynamicRouter”/>
from(“jms:queue:order”) public class myDynamicRouter {
.dynamicRouter(bean(new MyRouter())); public String[] route(String body) {
return new String[] { “file://backup”, .... }

XML DSL In XML DSL we have to define the bean as a regular spring bean. }
<bean id=”router” class=”com.foo.MyRouter”/> }
Which we then can refer to in the <dynamicRouter> tag. Annotation In the CustomerService, class we annoate the whereTo method with
<route> DSL @RecipientList and return a single destination based on the customer id.
<from uri=”jms:queue:order”/> Notice the flexibility of Camel as it can adapt accordingly to how you define
<dynamicRouter> what your methods are returning: a single element, a list, an iterator, etc.
<method ref=”router”/>
</dynamicRouter> public class CustomerService {
</route> @RecipientList
public String whereTo(@Header(“customerId”) id) {
Annotation You can use @DynamicRouter annotation in a bean to turn it into a dynamic router. return “jms:queue:customer:” + id;
DSL }

public class MyRouterBean {
}
@DynamicRouter
public String route(Exchange exchange) { And then we can route to the bean and it will act as a dynamic recipient list.
// query a data store to find where we should go next. from(“jms:queue:inbox”)
Return null to indicate end. .bean(CustomerService.class, “whereTo”);
}
}

DZone, Inc. | www.dzone.com


4 The Top Twelve Integration Patterns for Apache Camel

Splitter Java DSL Stock quote example


We want to update a website 5th second with the latest stock quotes. The
How can a component avoid receiving unwanted messages? quotes are received on a JMS topic. As we can receive multiple quotes for the
same stock within this time period we only want to keep the last one as its the
most up to date. We can do this with the aggregator:
from(“jms:topic:stock:quote”)
.aggregate()
.xpath(“/quote/@symbol”)
.completionInterval(5000)
.to(“direct:quotes”);
Order Order Order
New Order As the correlation expression we use XPath to fetch the stock symbol from the
Splitter Item 1 Item 2 Item 3 message body. As the aggregation strategy we use the default provided by
Problem How can we split a single message into pieces to be routed individually? Camel that picks the latest message, and thus also the most up to date. To
trigger the outgoing messages to be published we use a completion interval set
Solution Use a Splitter to break out the composite message into a series of individual to 5 seconds.
messages, each containing data related to one item. Loan broker example
We aggregate responses from various banks for their quote for a given loan
Camel Camel has support for Splitter using the split node.
request. We want to pick the bank with the best quote (the cheapest loan),
Java DSL In this route, we consume files from the inbox folder. Each file is then split into therefore we need to base our aggregation strategy to pick the best quote.
a new message. We use a tokenizer to split the file content line by line based from(“jms:topic:loan:quote”)
on line breaks. .aggregate()
from(“file://inbox”) .header(“loanId”)
.split(body().tokenize(“\n”)) .aggregationStrategy(bestQuote)
.to(“seda:orderLines”); .completionSize(3)
.to(“direct:bestLoanQuote”);
TIP: Camel also supports splitting streams using the streaming node. We can
split the stream by using a comma: We wish to trigger completion when we have received 3 quotes to pick the best
among. The following shows the code snippet for the aggregation strategy we
.split(body().tokenize(“,”)).streaming().
must implement to pick the best quote:
to(“seda:parts”);
public class BestQuoteStrategy implements
TIP: In the routes above each individual split message will be executed in
AggregationStrategy {
sequence. Camel also supports parallel execution using the parallelProcessing
public Exchange aggregate(Exchange oldExchange, Exchange
node.
newExchange) {
.split(body().tokenize(“,”)).streaming() double oldQuote = oldExchange.getIn().getBody(Double.
.parallelProcessing().to(“seda:parts”); class);
double newQuote = newExchange.getIn().getBody(Double.
XML DSL In this route, we use XPath to split XML payloads received on the JMS order class);
queue. // return the “winner” that has the lowest quote
<route> return newQuote < oldQuote ? newExchange : oldExchange;
<from uri=”jms:queue:order”/> }
<split> }
<xpath>/invoice/lineItems</xpath>
<to uri=”seda:processOrderLine”/> XML DZL Stock quote example
</split>
 <route>
</route> <from uri=”jms:topic:stock:quote”/>
<aggregate completionInterval=”5000”>
And in this route we split the messages using a regular expression: <correlationExpression>
<route> <xpath>/quote/@symbol</xpath>
<from uri=”jms:queue:order”/> </correlationExpression>
<split> <to uri=”direct:quotes”/>
<tokenizer token=”([A-Z|0-9]*);” regex=”true”/> </aggregate>
<to uri=”seda:processOrderLine”/> </route>
</split> Loan Broker Example
</route> <bean id=”bestQuote” class=”com.mycompany.
BestQuoteStrategy”/>
TIP: Split evaluates an org.apahce.camel.Expression to provide
<route>
something that is iterable to produce each individual new message. This
<from uri=”jms:topic:loan:qoute”/>
allows you to provide any kind of expression such as a Bean invoked as a
<aggregate strategyRef=”bestQuote” completionSize=”3”>
method call.
<correlationExpression>
<split>
<header>loanId</header>
<method bean=”mySplitter” method=”splitMe”/>
</correlationExpression>
<to uri=”seda:processOrderLine”/>
<to uri=”seda:bestLoanQuote”/>
</split>
</aggregate>
<bean id=”mySplitter” class=”com.mycompany. </route>
MySplitter”/>
TIP: The aggregate supports 5 different types of completions such as based
public List splitMe(String body) { on timeout, inactivity, a predicate, or size. You can use configure multiple
// split using java code and return a List completions such as a timeout and a size.
List parts = ...
return parts; TIP: If the completed predicate is more complex we can use a method call to
} invoke a bean so we can do the evaluation in pure Java code:
<bean id=”quoteService” class=”com.foo.QuoteService”/>
Aggregator public boolean isComplete(String body) {
return body.equals(“STOP”);
How do we combine the results of individual, but related messages so that they }
can be processed as a whole? <completionPredicate>
<method bean=”quoteService” method=”isComplete”/>
</completionPredicate>
Which can be even simpler using the Simple expression language:
<completionPredicate>
<simple>${body} == STOP</simple>
Inventory Inventory Inventory </completionPredicate>
Item 1 Item 2 Item 3 Inventory
Aggregator Order Resequencer
Problem How do we combine multiple messages into a single combined message?
How can we get a stream of related but out-of-sequence messages back into
Solution Use a stateful filter, an Aggregator, to collect and store individual messages until the correct order?
it receives a complete set of related messages to be published.

Camel Camel has support for the Aggregator using the aggregate method. A
correlation expression is used to determine which messages are related.
An aggregation strategy is used to combine aggregated messages into the
outgoing message. Camel’s aggregator also supports a completion predicate
allowing you to signal when the aggregation is complete.

Resequencer

DZone, Inc. | www.dzone.com


5 The Top Twelve Integration Patterns for Apache Camel

Problem How do we ensure ordering of messages? Camel, TIP: See Exception Clause for selective interception of thrown exception. This
continued allows you to route certain exceptions differently or even reset the failure by
Solution Use a stateful filter, a Resequencer, to collect and reorder messages so that they marking it as handled.
can be published in a specified order.
TIP: DeadLetterChannel supports processing the message before it gets
Camel Camel has support for the Resequencer using the resequence node. Camel redelivered using onRedelivery. This allows you to alter the message
uses a stateful batch processor that is capable of reordering related messages. beforehand (i.e. to set any custom headers).
Camel supports two resequencing algorithms:
Java DSL Global scope
batch: collects messages into a batch, sorts the messages and publishes the In global scope error handlers is defined before routes and applies to any routes
messages. which has not a route specific error handler.
stream: reorders, continuously, message streams based on detection of gaps
between messages. errorHandler(deadLetterChannel(“file:error”)
Batch is similar to the aggregator but with sorting. Stream is the traditional .maximumRedeliveries(3));
Resequencer pattern with gap detection. Stream requires usage of number
(longs) as sequencer numbers, enforced by the gap detection, as it must be from(...)
able to compute if gaps exist. A gap is detected if a number in a series is
missing, (e.g. 3, 4, 6 with number 5 missing). Camel will back off the messages Route scope
until number 5 arrives. In route scope the error handler is defined inside the route and applies only to
the given route.
Java DSL Batch:
We want to process received stock quotes, once a minute, ordered by their from(“jms:queue:event”)
stock symbol. We use XPath as the expression to select the stock symbol, as the .errorHandler(deadLetterChannel(“file:error/event”)
value used for sorting. .maximumRedeliveries(5).redeliveryDelay(5000))
from(“jms:topic:stock:quote”) // and here begins the route
.resequence().xpath(“/quote/@symbol”) .to(“log:event”)
.timeout(60 * 1000) .to(“bean:handleEvent”);
.to(“seda:quotes”);
XML DSL Global scope
Camel will default the order to ascending. You can provide your own To use global scoped error handler you refer to it using the errorHandlerRef
comparison for sorting if needed. attribute on the <camelContext> tag as shown:
Stream: <camelContext errorHandlerRef=”eh”>
Suppose we continuously poll a file directory for inventory updates, and it’s <errorHandler id=”eh” type=”DeadLetterChannel”
important they are processed in sequence by their inventory id. To do this we deadLetterUri=”file:error”>
enable streaming and use one hour as the timeout. <redeliveryPolicy maximumRedeliveries=”3”/>
</errorHandler>
from(“file://inventory”) <route>
.resequence().xpath(“/inventory/@id”) ...
.stream().timeout(60 * 60 * 1000) </route>
.to(“seda:inventoryUpdates”); </camelContext>
XML DSL Batch: Route scope
<route> Route scope is likewise configured by referring to an error handler using
<from uri=”jms:topic:stock:quote”/> errorHandlerRef attribute on the <route> tag as shown:
<resequence> <route errorHandlerRef=”other-eh”>
<xpath>/quote/@symbol</xpath> ...
<batch-config batchTimeout=”60000”/> </route>
</resequence>
<to uri=”seda:quotes”/>
</route> Wire Tap
Stream: How do you inspect messages that travel on a point-to-point channel?
<route>
<from uri=”file://inventory”/>
<resequence>
<xpath>/inventory/@id</xpath>
<stream-config timeout=”3600000”/> Source Destination
</resequence>
<to uri=”seda:quotes”/>
</route>
Notice that you can enable streaming by specifying <stream-config> instead
of <batch-config>.

Dead Letter Channel


What will the messaging system do with a message it cannot deliver?

Problem How do you tap messages while they are routed?


Delivery Fails
Solution Insert a Wire Tap into the channel that publishes each incoming message to the
main channel as well as to a secondary channel.

Camel Camel has support for Wire Tap using the wireTap node that supports two
modes: traditional and new message. The traditional mode sends a copy of the
original message, as opposed to sending a new message. All messages are sent
Sender Message as Event Message and run in parallel with the original message.
Channel Intended
Receiver Java DSL Traditional
The route uses the traditional mode to send a copy of the original message to
Reroute Delivery the seda tapped queue, while the original message is routed to its destination,
the process order bean.
from(“jms:queue:order”)
Dead Dead Letter .wireTap(“seda:tappedOrder”)
Message Channel 
 .to(“bean:processOrder”);
New message
Problem The messaging system cannot deliver a message In this route, we tap the high-priority orders and send a new message
containing a body with the from part of the order.

Solution When a message cannot be delivered it should be moved to a Dead Letter Channel

Camel Camel has extensive support for Dead Letter Channel by its error handler and Tip: As Camel uses an Expression for evaluation you can use other functions
exception clauses. Error handler supports redelivery policies to decide how many than xpath; for instance to send a fixed String, you can use constant.
times to try redelivering a message, before moving it to a Dead Letter Channel.
from(“jms:queue:order”)
The default Dead Letter Channel will log the message at ERROR level and .choice()
perform up to 6 redeliveries using a one second delay before each retry. 
 .when(“/order/priority = ‘high’”)

Error handlers have two-level scope at either global or route. .wireTap(“seda:from”, xpath(“/order/from”))
TIP: The Camel in Action book, chapter 5 is devoted to cover error handling, 
 .to(“bean:processHighOrder”);
which is the best source for information 
 .otherwise()

 .to(“bean:processOrder”);

DZone, Inc. | www.dzone.com


6 The Top Twelve Integration Patterns for Apache Camel

XML DSL Traditional


<route>
CONCLUSION
<from uri=”jms:queue:order”/>
<wireTap uri=”seda:tappedOrder”/>
<to uri=”bean:processOrder”/>
 The 12 patterns in this Refcard cover the often used patterns in
</route> the integration space. In this Refcard, you saw some of the great
New Message
powers of the EIP patterns and what you can do when using them
<route> in practice with Apache Camel. You can find more examples
<choice> of using EIPs at the Camel website: http://camel.apache.org/
<when> enterprise-integration-patterns.html. For more details about
<xpath>/order/priority = ‘high’</xpath>
<wireTap uri=”seda:from”>
Camel, we highly recommend the book Camel in Action.
<body><xpath>/order/from</xpath></body>
</wireTap> Get More Information
<to uri=”bean:processHighOrder”/> Camel website The home of the Apache Camel project. Find downloads, tutorials, examples,
</when> http://camel.apache.org getting started guides, issue tracker, roadmap, and mailing lists.
<otherwise>
FuseSource website The home of the FuseSource company, the professional company behind
<to uri=”bean:processOrder”/> http://fusesource.com Apache Camel with enterprise offerings, subscription, support, consulting,
</otherwise> training, getting started guides, webinars, and tooling.
</choice>
Camel in Action website The home of the Camel in Action book, published by Manning. The book is
</route> http://manning.com/ibsen also on sale at Amazon and other retailers.

About Author The personal blog of the author of this reference card. You can follow the
http://davsclaus.blogspot.com author on twitter @davsclaus.

ABOUT THE AUTHOR RECOMMENDED BOOK


Claus Ibsen is a principal engineer working Camel in Action is a Camel tutorial full of
for FuseSource Corporation specializing small examples showing how to work with
in the enterprise integration space. Claus the integration patterns. It starts with core
focuses mostly on Apache Camel and concepts like sending, receiving, routing
FUSE-related products. Claus has been and transforming data. It then shows you
engaged with Camel since late 2007, and the entire lifecycle and goes in depth on
he’s co-author of the Camel in Action book, how to test, deal with errors, scale, deploy,
published by Manning. Claus is very active and even monitor your app—details you
in the Apache and FUSE communities, can find only in the Camel code itself.
writing blogs, twittering and assisting on Written by the developers of Camel, this
the forums and irc channels. Claus is lead book distills their experiences and practical
on Apache Camel and drives the roadmap. insights so that you can tackle integration
You will be able to meet Claus at various tasks like a pro.
conferences where he speaks about Camel.

#82

Browse our collection of over 100 Free Cheat Sheets


Get More Refcardz! Visit refcardz.com

CONTENTS INCLUDE:


About Cloud Computing
Usage Scenarios Getting Started with

Aldon Cloud#64Computing

Underlying Concepts
Cost
by...

Upcoming Refcardz
youTechnologies ®

Data
t toTier
brough Comply.
borate.
Platform Management and more...

Chan
ge. Colla By Daniel Rubio

on:
dz. com

grati s
also minimizes the need to make design changes to support
CON
ABOUT CLOUD COMPUTING one time events. TEN TS
INC

s Inte -Patternvall

HTML LUD E:
Basics
Automated growthHTM
ref car

Web applications have always been deployed on servers & scalable


L vs XHT technologies

nuou d AntiBy Paul M. Du



Valid
ation one time events, cloud ML
connected to what is now deemed the ‘cloud’. Having the capability to support

RichFaces
Usef

ContiPatterns an

computing platforms alsoulfacilitate


Open the gradual growth curves
Page ■
Source
Vis it

However, the demands and technology used on such servers faced by web applications.Structure Tools

Core
Key ■

Structur Elem
E: has changed substantially in recent years, especially with al Elem ents
LUD
TS INC gration the entrance of service providers like Amazon, Google and Large scale growth scenarios involvingents
specialized
and mor equipment
rdz !

ous Inte Change

HTML
Microsoft. es e... away by
(e.g. load balancers and clusters) are all but abstracted
Continu at Every to isolat
e chang
ns
oftware i-patter relying on a cloud computing platform’s technology.
space

CSS3
n
Re fca

riptio e Work
Ant These companies Desc have a Privat
are in long deployed
itory
webmana applications
ge HTM
ns and lop softw n-con
trol repos to L BAS
trol that adapt and scale
Deve
les toto large user
a versio ing and making them
bases, In addition, several cloud computing ICSplatforms support data
n Con ment Patte
rn
it all fi minim
ize merg
HTM
e... le
Manage s and mor e Work knowledgeable in amany ine to
mainl aspects related tos multip
cloud computing. tier technologies that Lexceed the precedent set by Relational
space Comm and XHT
re

tice Privat lop on that utilize HTML MLReduce,


d Prac
Deve code lines a system Database Systems (RDBMS): is usedMap are web service APIs,
as thescalethe By An
sitory of work prog foundati
Ge t Mo

Repo
This Refcard active
will introduce are within
to you to cloud riente computing, with an
ION d units etc. Some platforms ram support large grapRDBMS deployments. The src
dy Ha
softw
EGRAT e ine loping task-o it and Java s written in hical on of
all attribute
softwar emphasis onDeve es by
Mainl
OUS
INT these ines providers, so youComm can better understand
also rece JavaScri user interfac web develop and the rris

Lucene
codel chang desc
ding e code Task Level as the
w ww.dzone.com

NTINU s of buil control what it is a cloudnize


line Policy sourc es as aplatform
computing can offer your ut web output ive data pt. Server-s e in clien ment. the ima alt attribute ribes whe
T CO ces ion Code Orga it chang e witho likew mec ide lang t-side ge is describe re the ima
hanism. fromAND
name
the pro ject’s vers CLOUD COMPUTING PLATFORMS
subm e sourc
applications. ise
ABOU (CI) is evel Comm
it and with uniqu softw
are from
was onc use HTML
web
The eme pages and uages like Nested
unavaila
ble. s alte ge file
a pro the build build um
UNDERLYING CONCEPTS rnate can be
Inte gration ed to blem Task-L Label ies to
all activition to the
bare
minim e
standard a very loos
and XHT rging use HTM PHP Tags tags text that found,
ous com mitt a pro USAGE SCENARIOS ate cies ML as Ajax L can is disp
to Autom configurat t
ization, ely-defi thei tech
Continu ry change cannot be (and freq
nden ymen layed
tion Build al depe need ned lang r visual eng nologies
a solu ineffective
deplo t
Label manu d tool the same for stan but as if
(i.e., ) nmen overlap
eve , Build stalle
t, use target enviro Amazon EC2: Industry standard it has
software and uagvirtualization ine. HTM uen
with terns ns (i.e.
blem ated ce pre-in whether dards e with b></ , so <a>< tly are) nest
lar pro that become
Autom Redu ymen a> is
ory. via pat d deploEAR) in each has L

Spring Roo
reposit -patter particu s cies Pay only what you consume
tagge or Amazon’s cloud
the curr you cho platform
computing becisome
heavily based moron very little fine. b></ ed insid
lained ) and anti x” the are solution duce
nden For each (e.g. WAR es t
ent stan ose to writ more e imp a></ e
not lega each othe
b> is
be exp text to “fi
al Depeapplication deployment
Web ge until
nden a few years
t librari agonmen
t enviro was similar that will software
industry standard and virtualization apparen ortant, the
e HTM technology.
CI can ticular con used tterns to pro can
Minim
rity
packa
all depe that all
targe dard s will L t. HTM l, but r. Tags
es i-pa tend but to most phone services: plans with late alloted resources,
simp or Reg L VS XH
ts with an
y Integ alize file
s. Ant , they and XHT lify all help XHTML, ardless <a><
in a par hes som
etim ctices,
Binar Centr temp your you prov TML b></
proces in the end bad pra enting
nt nmen
incurred cost
geme whether e a single based on
Creatsuchareresources were consumed
t enviro orthenot. Virtualization
muchallows MLaare physical othe
piece ofr hardware to be understand of HTML
approac ed with the cial, but, rily implem nden
cy Mana rties nt targe es to of the actually web cod ide a solid ing has
essa d to Depe prope into differe chang
utilized by multiple operating
function systems.simplerThis allows ing.resourcesfoundati job adm been arou
efi nec itting
associat to be ben
er
pare te builds commo
are not Fortuna
late Verifi e comm than on
ality be allocated nd for
n com Cloud computing asRun it’sremo
known etoday has changed this. expecte irably, that
befor
They they
etc.
(e.g. bandwidth, elem CPU) tohas
nmemory, exclusively totely
Temp
job has some time
Build
lts whe
ually,
appear effects. rm a
Privat y, contin nt team Every mov
entsinstances. ed to CSS
used
to be, HTML d. Earl
ed resu gration
The various resourcesPerfo consumed by webperio applications
dicall (e.g.
opme page system
individual operating bec Brow y exp . Whi
adverse unintend d Builds sitory Build r to devel common (HTM . ause ser HTM anded le it
ous Inte web dev manufacture L had very far mor has done
Stage Repo
e bandwidth, memory, CPU) areIntegtallied
ration on a per-unit CI serve basis L or XHT
produc Continu Refcard
e Build rm an ack from extensio .) All are
e.com

ML shar limit e than its


pat tern. term this
Privat
(starting from zero) by Perfo all majorated cloud
feedb computing platforms.
occur on As a user of Amazon’s
n. HTM EC2 essecloud
ntiallycomputing platform, you are
es cert result elopers
came
rs add
ed man ed layout anybody
the tion the e, as autom they based proc is
gra such wayain The late a lack of stan up with clev y competi
supp
of as
” cycl Build Send builds
assigned esso
an operating L system
files shou in theplai
same as onelemallents
hosting
ous Inte tional use and test concepts
soon n text ort.
ration ors as ion with r
Integ entat
ld not in st web dar er wor ng stan
Continu conven “build include oper
docum
be cr standar kar dar
the to the to rate devel
While s efer of CI
ion
Gene
Cloud Computing

the not

DZone, Inc.
s on
expand

ISBN-13: 978-1-936502-03-5
140 Preston Executive Dr. ISBN-10: 1-936502-03-8
Suite 100 50795
Cary, NC 27513
DZone communities deliver over 6 million pages each month to 888.678.0399
more than 3.3 million software developers, architects and decision 919.678.0300
makers. DZone offers something for everyone, including news,
Refcardz Feedback Welcome
$7.95

tutorials, cheat sheets, blogs, feature articles, source code and more.
refcardz@dzone.com 9 781936 502035
“DZone is a developer’s dream,” says PC Magazine.
Sponsorship Opportunities
Copyright © 2011 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a
retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, sales@dzone.com Version 1.0
without prior written permission of the publisher.

You might also like