camel overview

35
1 Implemen(ng Enterprise Integra(on Pa3erns through Apache Camel James Strachan, Red Hat Friday, February 8, 2013

Upload: strachaj

Post on 13-Jul-2015

488 views

Category:

Documents


2 download

TRANSCRIPT

1

Implemen(ng  Enterprise  Integra(on  Pa3erns  through  Apache  Camel  

James  Strachan,  Red  Hat

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Your  speaker  today

James  Strachan• [email protected]

• twi8er:  @jstrachan

• blog:  h8p://macstrac.blogspot.com/

Senior  Consul(ng  SoFware  Engineer  at  Red  Hat• leaders  in  open  source  middleware  &  integra?on

• we  provide  training,  consul?ng,  support,  distribu?ons  &  tools  for  open  source  integra?on  soCware

Open  Source  hacker• created  the  Groovy  programming  language

• created  Apache  Camel

• co-­‐founder  of– Apache  Ac(veMQ,  ServiceMix,  Geronimo

– Scalate

• lets  not  men?on  Jelly  :)

2

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

What  are  Enterprise  Integra?on  Pa8erns?

3

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Book  by  Gregor  &  Bobby!

4

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

A  selec?on  of  some  of  the  pa8erns...

5

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

What  is  Apache  Camel?

http://camel.apache.org/

6

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

What  is  Apache  Camel?

7

Apache  Camel  is  a  Powerful  Open  SourceIntegra(on  Framework

based  on  knownEnterprise  Integra(on  Pa3erns  

h3p://camel.apache.org/enterprise-­‐integra(on-­‐pa3erns.html

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Lets  look  at  a  pa8ern!

8

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Message  Filter

9

Friday, February 8, 2013

<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="activemq:topic:Quotes"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri="mqseries:WidgetQuotes"/> </filter> </route> </camelContext>

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Message  Filter  :  XML

10

Friday, February 8, 2013

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="activemq:topic:Quotes"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri="mqseries:WidgetQuotes"/> </filter> </route> </camelContext>

</beans>

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Message  Filter  :  Spring  XML

11

Friday, February 8, 2013

<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="activemq:topic:Quotes"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri="mqseries:WidgetQuotes"/> </filter> </route> </camelContext>

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Message  Filter  :  XML

12

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Expressions  &  Predicates

13

15 ExpressionLanguages BeanShell Python

EL RubyGroovy Simple

JavaScript SpELJSR 223 SQLOGNL XPathMVEL XQueryPHP

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

URIs,  Endpoints  and  Components  (120+)

14

h8p://camel.apache.org/components.html

activemq cxf flatpack jasyptactivemq-journal cxfrs freemarker javaspace

amqp dataset ftp/ftps/sftp jbiatom db4o gae jcrbean direct hdfs jdbc

bean validation ejb hibernate jettybrowse esper hl7 jmscache event http jmx

cometd exec ibatis jpacrypto file irc jt/400

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

120+  components...

15

language properties seda stream

ldap quartz servlet string-template

mail/imap/pop3 quickfix 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

Friday, February 8, 2013

<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="activemq:topic:Quotes"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri="mqseries:WidgetQuotes"/> </filter> </route> </camelContext>

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Message  Filter  :  XML

16

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Message  Filter  :  Java

from("activemq:topic:Quotes”). filter().xpath("/quote/product = ‘widget’"). to("mqseries:WidgetQuotes");

17

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

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

}}

18

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Message  Filter  :  Scala  

"direct:a" when(_.in == "<hello/>") { to("mock:a")}

19

Friday, February 8, 2013

<camelContext xmlns="http://camel.apache.org/schema/spring"> <package>com.acme.quotes</package></camelContext>

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Create  CamelContext  in  Spring

20

Friday, February 8, 2013

CamelContext context = new DefaultCamelContext();context.addRoutes(new MyRouteBuilder());context.start();

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Create  CamelContext  in  Java

21

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

IDE  support

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

IDE  support  (XML)

23

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Recap  -­‐  core  concepts  of  Camel

24

Enterprise  Integra(on  Pa3erns

Rou(ng

Domain  Specific  Language  (DSL)

Endpoints  &  URIs

Predicates  &  Expressions

Components  (lots  of  ‘em!)

Test  Kit

             and  much  more  ...

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Beans

25

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Bean  as  a  Message  Translator

from("activemq:Incoming”). beanRef("myBeanName”, “someMethod"). to("activemq:Outgoing");

26

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Bean  

public class Foo {

public String someMethod(String name) { return “Hello “ + name; }}

27

Friday, February 8, 2013

public class Foo {

@Consume(uri="activemq:cheese") public Object onCheese(String name) { ... }}

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Binding  Beans  to  Camel  Endpoints

28

Friday, February 8, 2013

public class Foo {

public Object onCheese( @XPath("/foo/bar") String name, @Header("JMSCorrelationID") String id) { ... }}

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Binding  Method  Arguments

for  more  annota(ons  seeh3p://camel.apache.org/bean-­‐integra(on.html

29

Friday, February 8, 2013

public class Foo { @Produce(uri="activemq:foo.bar") ProducerTemplate producer;

public void doSomething() { if (whatever) { producer.sendBody("<hello>world!</hello>"); } }}

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Sending  messages  to  endpoints

30

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Sending  messages  to  endpoints

public interface MyListener { String sayHello(String name);}

public class MyBean { @Produce(uri = "activemq:foo") protected MyListener producer;

public void doSomething() { // lets send a message String response = producer.sayHello("James"); }}

31

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Fastest  way  to  learn....

Manning  top-­‐15  year  to  date  (2010)

#10 #12Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Fuse  IDE:  the  fastest  way  to  get  riding!

free  eclipse  based  tool  for  Apache  Camel  &  Ac(veMQ  etc• create  projects,  edit  routes,  run  stuff,  visualise,  trace  &  diagnose

h3p://fusesource.com/

33

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Summary:  Camel  rocks

Ride  that  Camel• h8p://camel.apache.org/

Download  Fuse  IDE• h8p://fusesource.com

Buy  the  book!   Don’t  get  the  hump!

34

Friday, February 8, 2013

Copyright  ©  2013  Red  Hat,  Inc.  All  rights  reserved.  

Any  Ques(ons?

35

twi3er:  @jstrachan  #fusenews

h3p://fusesource.com

Friday, February 8, 2013