camel as a_glue

22
Camel as a Glue

Upload: andriy-andrunevchyn

Post on 25-May-2015

1.982 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Camel as a_glue

Camelas a Glue

Page 2: Camel as a_glue

Project. How we planned it

Page 3: Camel as a_glue

Project. How we imagine it.

Page 4: Camel as a_glue

Project. In practice.

Page 5: Camel as a_glue

Integration project. In practice.

Page 6: Camel as a_glue

How to handle it?

Page 7: Camel as a_glue
Page 10: Camel as a_glue

Apache Camel. Pros.

Pros• Lighweight• A lot components• Support many Data Formats• Good community• DSL(XML, Java, Scala, Groovy)• Spring integration

Page 11: Camel as a_glue

Apache Camel. Cons.

• Messy documentations

Page 12: Camel as a_glue

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>

Page 13: Camel as a_glue

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");

} };

Page 14: Camel as a_glue

Processor

@Component(“urlHandler”)public class UrlHandler{

public void handle(Exchange ex){ex.getIn();//handle input

}}

Page 15: Camel as a_glue

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>

Page 16: Camel as a_glue

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

Page 17: Camel as a_glue

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>

Page 18: Camel as a_glue

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

Page 19: Camel as a_glue

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>

Page 22: Camel as a_glue

Questions?