riding apache camel
DESCRIPTION
TRANSCRIPT
![Page 2: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/2.jpg)
About author
• Apache CXF commiter and PMC member
• Apache Camel commiter and PMC member
![Page 3: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/3.jpg)
Riding Apache Camel
•What's Camel
•EIP Examples
•Beans, Type Conversion , Data Format
•Some tips of Camel Riding
![Page 5: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/5.jpg)
What is Camel?
•A Camel can carry 4 times as much load as other beasts of burden!
•Apache Camel is a powerful Spring based Integration Framework.
•Camel implements the Enterprise Integration Patterns allowing you to configure routing and mediation rules in either a Java based Domain Specific Language (or Fluent API) or via Spring based Xml Configuration files. Either approaches mean you get smart completion of routing rules in your IDE whether in your Java or XML editor.
•Apache Camel uses URIs so that it can easily work directly with any kind of Transport or messaging model such as HTTP, ActiveMQ, JMS, JBI, MINA or CXF together with working with pluggable Data Format options. Apache Camel is a small library which has minimal dependencies for easy embedding in any Java application.
![Page 6: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/6.jpg)
Book by Gregor & Bobby!
![Page 7: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/7.jpg)
Message Routing
![Page 8: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/8.jpg)
Message Routing in EIP
![Page 9: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/9.jpg)
Camel Components
![Page 10: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/10.jpg)
Simple Routing
![Page 11: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/11.jpg)
More Simple Routing
![Page 12: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/12.jpg)
Pipeline
![Page 13: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/13.jpg)
Multicast Routing
![Page 14: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/14.jpg)
Some examples of the EIP implemation
![Page 15: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/15.jpg)
Message Filter
![Page 16: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/16.jpg)
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="activemq:topic:Quotes"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri="mqseries:WidgetQuotes"/> </filter> </route> </camelContext>
Message Filter
from("activemq:topic:Quotes). filter().xpath("/quote/product = ‘widget’"). to("mqseries:WidgetQuotes");
![Page 17: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/17.jpg)
Language Support For Message Processing
• BeanShell
• Javascript
• Groovy
• Python
• PHP
• Ruby
• JSP EL
• OGNL
• SQL
• Xpath
• XQuery
![Page 18: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/18.jpg)
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"> <camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="activemq:topic:Quotes"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri="mqseries:WidgetQuotes"/> </filter> </route> </camelContext>
</beans>
Message Filter : Spring XML
![Page 19: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/19.jpg)
Message Filter : Java Complete
package com.acme.quotes;
import org.apache.camel.builder.RouteBuilder;
public class MyRouteBuilder extends RouteBuilder { public void configure() {
// forward widget quotes to MQSeries from("activemq:topic:Quotes). filter().xpath("/quote/product = ‘widget’"). to("mqseries:WidgetQuotes"); }}
![Page 20: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/20.jpg)
CamelContext context = new DefaultCamelContext();context.addRoutes(new MyRouteBuilder());context.start();
Starting the CamelContext
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:start"/> <choice> <when> <xpath>$destination = 'firstChoice'</xpath> <to uri="mock:matched"/> </when> <otherwise> <to uri="mock:notMatched"/> </otherwise> </choice> </route> </camelContext>
![Page 21: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/21.jpg)
Content Base Router
from("activemq:NewOrders”). choice().when("/quote/product = ‘widget’"). to("activemq:Orders.Widgets"). choice().when("/quote/product = ‘gadget’"). to("activemq:Orders.Gadgets"). otherwise().to("activemq:Orders.Bad");
![Page 22: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/22.jpg)
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="activemq:NewOrders"/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri="activemq:Orders.Widgets"/> </when> <when> <xpath>/order/product = 'gadget'</xpath> <to uri="activemq:Orders.Gadgets"/> </when> <otherwise> <to uri="activemq:Orders.Bad"/> </otherwise> </choice> </route> </camelContext>
Content Based Router
![Page 23: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/23.jpg)
How camel do this routing work ?•Camel Components
•Camel Endpoints
•Camel Consumer
•Camel Producer
•Camel-Core
![Page 24: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/24.jpg)
How camel do this routing work ?
http://activemq.apache.org/camel/architecture.html
![Page 25: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/25.jpg)
Beans
![Page 26: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/26.jpg)
Bean as a Message Translator
from("activemq:Incoming”). beanRef("myBeanName"). to("activemq:Outgoing");
![Page 27: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/27.jpg)
Bean
public class Foo {
public void someMethod(String name) { ... }}
![Page 28: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/28.jpg)
Bean as a Message Translator with method name
from("activemq:Incoming”). beanRef("myBeanName", "someMethod"). to("activemq:Outgoing");
![Page 29: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/29.jpg)
public class Foo {
@MessageDriven(uri="activemq:cheese") public void onCheese(String name) { ... }}
Binding Beans to Camel Endpoints
![Page 30: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/30.jpg)
public class Foo {
public void onCheese( @XPath("/foo/bar") String name, @Header("JMSCorrelationID") String id) { ... }}
Binding Method Arguments
for more annotations seehttp://activemq.apache.org/camel/bean-integration.html
![Page 31: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/31.jpg)
Type Conversion
![Page 32: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/32.jpg)
package com.acme.foo.converters;
import org.apache.camel.Converter;import java.io.*;
@Converterpublic class IOConverter {
@Converter public static InputStream toInputStream(File file) throws FileNotFoundException { return new BufferedInputStream(new FileInputStream(file)); }}
Type Conversion
# META-INF/services/org/apache/camel/TypeConverter
com.acme.foo.converters
![Page 33: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/33.jpg)
protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from("direct:start").convertBodyTo(InputStream.class).to("mock:result"); } }; } protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from("direct:start").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(InputStream.class)); } }).to("mock:result"); }; }
Type Conversion
![Page 34: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/34.jpg)
Data Format
from("activemq:QueueWithJavaObjects). marshal().jaxb(). to("mqseries:QueueWithXmlMessages");
from("activemq:QueueTestMessage). marshal().zip(). to("mqseries:QueueWithCompressMessage");
from("activemq:QueueWithXmlMessages). unmarshal().jaxb(). to("mqseries:QueueWithJavaObjects");
![Page 35: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/35.jpg)
Riding tips of camel
![Page 36: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/36.jpg)
Camel Riding from Java
•/META-INF/spring/camelContext.xml
•set the CLASSPATH
•java org.apache.camel.spring.Main
![Page 37: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/37.jpg)
Maven Tooling
<project>... <build> <plugins> <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-maven-plugin</artifactId> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-maven-plugin</artifactId> </plugin> </plugins> </reporting></project>
mvn camel:run
![Page 38: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/38.jpg)
Maven Plugin Site Report
![Page 39: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/39.jpg)
Writing You Own Component
•Component
•Endpoint
•Consumer
•Provider
![Page 40: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/40.jpg)
Where would I use Camel?
•standalone or in any Spring application
•inside ActiveMQ’s JMS client or the broker
•inside your ESB such as ServiceMix via the servicemix-camel Service Unit
•inside CXF either as a transport or reusing CXF inside Camel
![Page 41: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/41.jpg)
How to write your routing rule in Camel
•What's the magic of from, to, choice ......
• /camel-core/src/main/java/org/apache/camel/model
•Implementing it in DSL way
• Defining the type class that you want
•Implementing it in a Spring configuration way
• Adding the annotation for JAXB consuming
![Page 42: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/42.jpg)
Questions?
![Page 43: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/43.jpg)
Let's take a look at Camel-CXF example
•Open eclipse and go to code please
•What does Camel-CXF example have ?
•Multi-binding and Multi-transport supporting
•LoadBalancing
•JAXWS WebSerivce Provider API
![Page 44: Riding Apache Camel](https://reader033.vdocuments.us/reader033/viewer/2022050920/54bc9b944a7959f6568b45fc/html5/thumbnails/44.jpg)
Where do I get more info?
please do take Camel for a ride!
http://activemq.apache.org/camel/
don’t get the hump! :-)