Weitere Àhnliche Inhalte
Ăhnlich wie Introduction to Apache Camel (20)
KĂŒrzlich hochgeladen (20)
Introduction to Apache Camel
- 1. Introduction to
Apache Camel
Bosanac Dejan
January 2011
A Progress Software
Company
- 2. About me
ï§ Bosanac Dejan
ï§ Senior Software Engineer at FUSESource - http://
fusesource.com
ï§ Apache ActiveMQ committer and PMC member
ï§ Co-author of ActiveMQ in Action
2 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 3. What is Apache Camel?
Apache Camel is a powerful Open Source Integration
Framework based on known Enterprise Integration Patterns
3 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 4. Why Apache Camel?
ï§ Integration can be messy - variety of protocols and
data formats
ï§ Framework hides all complexity so you can focus on
your business logic
4 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 5. Route example
Content Based Router
5 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 6. Content based Router - XML
<camelContext>
<route>
<from uri="activemq:NewOrders"/>
<choice>
<when>
<xpath>/order/product = 'widget'</xpath>
<to uri="activemq:Orders.Widgets"/>
</when>
<otherwise>
<to uri="activemq:Orders.Gadgets"/>
</otherwise>
</choice>
</route>
</camelContext>
6 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 7. Content Based Router - Java DSL
from("activemq:NewOrders")
.choice()
.when().xpath(â/order/product = 'widget'â)
.to(âactivemq:Orders.Widgetâ)
.otherwise()
.to(âactivemq:Orders.Gadgetâ);
7 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 8. 50 Enterprise Integration Patterns
http://camel.apache.org/enterprise-integration-patterns.html
8 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 9. 80 Components
http://camel.apache.org/components.html
activemq cxf ïŹatpack jasypt
activemq-journal cxfrs freemarker javaspace
amqp dataset ftp/ftps/sftp jbi
atom db4o gae jcr
bean direct hdfs jdbc
bean validation ejb hibernate jetty
browse esper hl7 jms
cache event http jmx
cometd exec ibatis jpa
crypto ïŹle irc jt/400
9 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 10. 80 Components
http://camel.apache.org/components.html
language properties seda stream
ldap quartz servlet string-template
mail/imap/pop3 quickïŹx sip test
mina ref smooks timer
mock restlet smpp validation
msv rmi snmp velocity
nagios rnc spring-integration vm
netty rng spring-security xmpp
nmr rss spring-ws xquery
printer scalate sql xslt
10 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 11. 19 Data Formats
http://camel.apache.org/data-format.html
bindy protobuf
castor serialization
csv soap
crypto syslog
dozer tidy markup
ïŹatpack xml beans
gzip xml security
hl7 xstream
jaxb zip
json
from("activemq:QueueWithJavaObjectsâ)
.marshal().jaxb()
.to("mq:QueueWithXmlMessages");
11 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 12. 14 Expression Languaes
http://camel.apache.org/languages.html
BeanShell PHP
EL Python
Groovy Ruby
JavaScript Simple
JSR 223 SQL
OGNL XPath
MVEL XQuery
12 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 13. DSL in 3 programming Languages
Java
from(A).filter(isWidget).to(B);
XML
<route>
<from ref="A"/>
<filter>
<xpath>/quote/product = âwidgetâ</xpath>
<to ref="B"/>
</filter>
</route>
Scala
from(A) filter(isWidget) --> B
13 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 14. Running Camel
Known Containers
ï§ Deployment Strategy
Apache ServiceMix
âą No container dependency
âą Lightweight Apache ActiveMQ
âą Embeddable Apache Tomcat
ï§ Deployment Options Jetty
âą Standalone
JBoss
âą WAR
âą Spring IBM WebSphere
âą J2EE
Oracle WebLogic
âą JBI
Oracle OC4j
âą OSGi
âą Cloud GlassïŹsh
Google App Engine
... others
14 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 15. Running Camel
Java Application
CamelContext context = new DefaultCamelContext();
context.addRoutes(new MyRouteBuilder());
context.start();
Spring Application
<camelContext>
<package>com.acme</package>
</camelContext>
15 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 16. Managing Camel
ï§ JMX API
ï§ REST API
Fuse HQ SOA management and monitoring system based on
Hyperic HQ Enterprise
16 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 17. Developer Web Console
17 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 18. FuseSource Rider
18 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 19. Rider Auto Parts Example by Jonathan Anstey
http://architects.dzone.com/articles/apache-camel-integration
19 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 20. Rider Auto Parts Example by Jonathan Anstey
http://architects.dzone.com/articles/apache-camel-integration
1
20 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 21. Rider Auto Parts Example by Jonathan Anstey
http://architects.dzone.com/articles/apache-camel-integration
1
2
21 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 22. Rider Auto Parts Example by Jonathan Anstey
http://architects.dzone.com/articles/apache-camel-integration
1
3
2
22 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 23. Rider Example - Spring ConïŹguration
<broker xmlns="http://activemq.apache.org/schema/core" persistent="false">
<transportConnectors>
<transportConnectoruri="tcp://localhost:61616" />
</transportConnectors>
</broker>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<bean id="helper" class="org.fusesource.camel.OrderHelper"/>
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<package>org.fusesource.camel</package>
</camelContext>
Â
23 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 24. Rider Example - Route 1
public class Route1 extends RouteBuilder {
public void configure() throws Exception {
from("ftp:user@rider.com?password=secret")
.to("activemq:queue:incoming");
}
}
24 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 25. Rider Example - Route 2
public class Route2 extends RouteBuilder {
public void configure() throws Exception {
from("jetty:http://localhost:8080/orders")
.inOnly("activemq:queue:incoming")
.transform().constant("OK");
}
}
25 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 26. Rider Example - Route 3
public class Route3 extends RouteBuilder {
public void configure() throws Exception {
JaxbDataFormat jaxb = new JaxbDataFormat("com.rider");
BindyDataFormat bindy = new BindyDataFormat("com.rider");
from("activemq:queue:incoming")
.convertBodyTo(String.class)
.choice()
.when().method("helperâ, "isXml")
.unmarshal(jaxb)
.to("activemq:queue:order")
.when().method("helperâ, "isCsv")
.unmarshal(bindy)
.to("activemq:queue:order")
}
}
26 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 27. Rider Example - Data Samples
XML Data
<?xml version="1.0" encoding="UTF-8"?>
<order name="motor" amount="1"/>
CSV Data
"name", "amount"
"brake pad", "2"
27 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 28. Rider Example - Order helper
public class OrderHelper {
public boolean isCsv(String body) {
return !body.contains("<?xml");
}
Â
public boolean isXml(String body) {
return body.contains("<?xml");
}
}
28 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 29. Rider Example - Order Bean
@XmlAccessorType(XmlAccessType.FIELD)
public class Order implements Serializable {
@XmlAttribute
private String name;
@XmlAttribute
private int amount;
Â
public Order() {
}
Â
public Order(String name, int amount) {
this.name = name;
this.amount = amount;
}
Â
@Override
public String toString() {
return "Order[" + name + " , " + amount + "]";
}
}
29 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 30. What else is there?
ï§ Error handling
ï§ EIP annotations
ï§ Test Kit
ï§ Transactions
ï§ Interceptors
ï§ Security
ï§ ...
30 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 31. More Information
ï§ Where do I get more information?
ï§ Camel website: http://camel.apache.org
ï§ Camel article: http://architects.dzone.com/articles/apache-camel-
integration
ï§ Camel in Action book: http://manning.com/ibsen
31 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 32. Blog:
http://www.nighttale.net/
Twitter:
http://twitter.com/dejanb
http://twitter.com/fusenews
32 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company
- 33. Questions?
Blog:
http://www.nighttale.net/
Twitter:
http://twitter.com/dejanb
http://twitter.com/fusenews
32 © 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software
Company