31
1 Implementing Enterprise Integration Patterns through Apache Camel Andrea Leoncini, Red Hat lunedì 18 febbraio 13

Camel and JBoss

Embed Size (px)

DESCRIPTION

Camel and JBoss Andrea Leoncini JBug Roma - Febraury 2013

Citation preview

Page 1: Camel and JBoss

1

Implementing Enterprise Integration Patterns through Apache Camel

Andrea Leoncini, Red Hat

lunedì 18 febbraio 13

Page 2: Camel and JBoss

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

Your speaker today

Andrea Leoncini• [email protected]• twitter: @leopericoli

Senior Middleware Solution Architect at Red Hat• leaders in open source middleware & integration• we provide training, consulting, support, distributions & tools for open

source integration software

In the community• co-founder of JUG Roma• co-founder of JBUG Roma, JBUG Milano• andrea.leoncini @JBoss Community• pride founder of JBoss Consulting Team in Italy

2

lunedì 18 febbraio 13

Page 3: Camel and JBoss

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

What are Enterprise Integration Patterns?

3

lunedì 18 febbraio 13

Page 4: Camel and JBoss

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

Book by Gregor & Bobby!

4

lunedì 18 febbraio 13

Page 5: Camel and JBoss

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

A selection of some of the patterns...

5

lunedì 18 febbraio 13

Page 6: Camel and JBoss

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

What is Apache Camel?

http://camel.apache.org/

6

lunedì 18 febbraio 13

Page 7: Camel and JBoss

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

What is Apache Camel?

7

Apache Camel is a Powerful Open Source

Integration Frameworkbased on known

Enterprise Integration Patterns

http://camel.apache.org/enterprise-integration-patterns.html

lunedì 18 febbraio 13

Page 8: Camel and JBoss

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

Lets look at a pattern!

8

lunedì 18 febbraio 13

Page 9: Camel and JBoss

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

Message Filter

9

lunedì 18 febbraio 13

Page 10: Camel and JBoss

<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

lunedì 18 febbraio 13

Page 11: Camel and JBoss

<?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

lunedì 18 febbraio 13

Page 12: Camel and JBoss

<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

lunedì 18 febbraio 13

Page 13: Camel and JBoss

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

Expressions & Predicates

13

15 ExpressionLanguages BeanShell Python

EL RubyGroovy Simple

JavaScript SpELJSR 223 SQLOGNL XPathMVEL XQueryPHP

lunedì 18 febbraio 13

Page 14: Camel and JBoss

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

URIs, Endpoints and Components (120+)

14

http://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

lunedì 18 febbraio 13

Page 15: Camel and JBoss

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

lunedì 18 febbraio 13

Page 16: Camel and JBoss

<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

lunedì 18 febbraio 13

Page 17: Camel and JBoss

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

Message Filter : Java

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

17

lunedì 18 febbraio 13

Page 18: Camel and JBoss

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

lunedì 18 febbraio 13

Page 19: Camel and JBoss

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

Message Filter : Scala

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

19

lunedì 18 febbraio 13

Page 20: Camel and JBoss

<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

lunedì 18 febbraio 13

Page 21: Camel and JBoss

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

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

Create CamelContext in Java

21

lunedì 18 febbraio 13

Page 22: Camel and JBoss

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

IDE support

lunedì 18 febbraio 13

Page 23: Camel and JBoss

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

IDE support (XML)

23

lunedì 18 febbraio 13

Page 24: Camel and JBoss

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

Recap - core concepts of Camel

24

Enterprise Integration Patterns Routing Domain Specific Language (DSL) Endpoints & URIs Predicates & Expressions Components (lots of ‘em!) Test Kit

and much more ...

lunedì 18 febbraio 13

Page 25: Camel and JBoss

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

Beans

25

lunedì 18 febbraio 13

Page 26: Camel and JBoss

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

Bean as a Message Translator

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

26

lunedì 18 febbraio 13

Page 27: Camel and JBoss

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

Bean

public class Foo {

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

27

lunedì 18 febbraio 13

Page 28: Camel and JBoss

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

lunedì 18 febbraio 13

Page 29: Camel and JBoss

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 annotations seehttp://camel.apache.org/bean-integration.html

29

lunedì 18 febbraio 13

Page 30: Camel and JBoss

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

lunedì 18 febbraio 13

Page 31: Camel and JBoss

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

lunedì 18 febbraio 13