camel as a_glue
TRANSCRIPT
Camelas a Glue
Project. How we planned it
Project. How we imagine it.
Project. In practice.
Integration project. In practice.
How to handle it?
RTFM.Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions
Specific tool
• Apache Camel• Spring Integration• Enterprise Service Bus (Mule ESB)
Read article
Apache Camel. Pros.
Pros• Lighweight• A lot components• Support many Data Formats• Good community• DSL(XML, Java, Scala, Groovy)• Spring integration
Apache Camel. Cons.
• Messy documentations
Basic example. XML DSLcamel-config.xml<camelContext>………………………………………………….
<route><from uri="servlet:///my_url" /><bean ref=“urlHandler” method=“handle" /><transform><constant>DONE</constant></transform>
</route>………………………………………………….</camelContext>
Basic example. JAVA DSL
public class MyRouteBuilder extends RouteBuilder{
public void configure() { from(" servlet:///my_url "). process(new UrlHandler()).to("direct:b");
} };Orpublic class MyRouteBuilder extends RouteBuilder{
public void configure() { from(" servlet:///my_url "). processRef(“urlHandler”).to("direct:b");
} };
Processor
@Component(“urlHandler”)public class UrlHandler{
public void handle(Exchange ex){ex.getIn();//handle input
}}
More complex example
<route><from uri="activemq:queue:queueName" /><unmarshal ref="xstream-utf8" /><bean ref=“firstProcessor" method="process" /><bean ref=“secondProcessor" method="process" />
…………………………………………………………………………………….<bean ref=“lastProcessor" method="process" /><to uri="direct:anotherRoute" />
</route>
Components• Amazon stack• Apache stack(service miz, fop, cxf,)• DBs(jdbc, jpa, ibatis)• EJB• File(ftp, ftps, file, hdfs)• Google stack(gae, guice, gmail, gtask)• Hazelcast• JMS• JMX• Mail (IMAP, POP)• Queues• Twitter• Many others
Components example
To poll, every 5 sec., all statuses on your home timeline and send to gmail:
Java DSLfrom("twitter://timeline/home?
type=polling&delay=5&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]").to("gmail://[email protected]")
XML DSL<route>
<from uri="twitter://timeline/home?type=polling&delay=5&consumerKey=[s]&consumerSecret=[s]&accessToken=[s]&accessTokenSecret=[s]"/> <to uri=" gmail://[email protected] "/>
</route>
Data Formats• Standard java serialization• Object marshalling (json, protobuf)• Object xml marshalling (xstream, jaxb, jixb, castor, xmlbeans• Object/XML/Webservice marshalling (SOAP)• Direct JSON / XML marshalling• Flat data structure marshalling (BeanIO, bindy, csv, edi, flatpack
dataformat)• Domain specific marshalling (HL7)• Compression (gzip, zip)• Security (Crypto, PGP, XMLsecurity)• Misc (custom dataformat, rss, syslog, tidymarkup)• Dozer Type Conversion
Marshalling example
<route> <from uri="direct:start"/><marshal ref="myJaxb"/> <to uri="direct:marshalled"/>
</route> <route>
<from uri="direct:marshalled"/> <unmarshal ref="myJaxb"/> <to uri="mock:result"/>
</route>
EIP
• Dynamic Router
• Recipient List
• Message Filter
• Wire Tap• Throttler• Load Balancer• Multicast• Others
Questions?