apache camel - wjax 2008

33
Leichtgewichtige Enterprise-Integration mit Apache Camel Christian Meder | inovex GmbH

Upload: inovex-gmbh

Post on 14-Jun-2015

2.259 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Apache Camel - WJax 2008

Leichtgewichtige Enterprise-Integration mit Apache Camel

Christian Meder | inovex GmbH

Page 2: Apache Camel - WJax 2008

Agenda

Warum Apache Camel ? Enterprise Integration Patterns Camel

– Konzepte

– DSL

– Beispiel

– Komponenten

– Möglichkeiten Fazit

Page 3: Apache Camel - WJax 2008

Enterprise-Integration

Enterprise ApplicationIntegration (EAI)

Service OrientedArchitecture (SOA)

Webservices(WS-*)

Enterprise ServiceBus (ESB)

Message OrientedMiddleware (MOM)

XML

SOAP

WSDL

HTTP

Binärformate

JMS

Page 4: Apache Camel - WJax 2008

Nur für Spezialisten ?

Page 5: Apache Camel - WJax 2008

Apache Camel

Page 6: Apache Camel - WJax 2008

Das Buch

Gregor Hohpe, Bobby WoolfEnterprise Integration Patterns

“The Bible for EnterpriseApplication Integration” (amazon.com)

Page 7: Apache Camel - WJax 2008

Cast

Page 8: Apache Camel - WJax 2008

Messaging

remove

• location dependencies

• data format dependencies

• temporal dependencies

Page 9: Apache Camel - WJax 2008

Enterprise Integration Patterns

• 65 patterns

• Messaging Endpoints

• Message Construction

• Messaging Channels

• Message Routing

• Message Transformation

• System Management

Page 10: Apache Camel - WJax 2008

Enterprise Integration Patterns (Basics)

• Channel

• Message

• Pipes and Filters

• Message Router

• Message Translator

• Message Endpoint

Page 11: Apache Camel - WJax 2008

EIP (Routing/Transformation)

• Message Filter

• Splitter

• Aggregator

• Resequencer

• Content Enricher

• Content Filter

• Normalizer

Page 12: Apache Camel - WJax 2008

Beispiel (VeS)

Vollständig erfundenes Stammdatensystem

Page 13: Apache Camel - WJax 2008

Apache Camel

Wurzeln in servicemix-eip, activemq activemq, servicemix, cxf communities implementiert 40 EIP camel-core: commons-logging, jaxb,

activation 1.3.0 April 2008 (208 tasks), 1.4.0 Juli 2008

(261 tasks), 1.5.0 Oktober 2008 (266 tasks) kommerzieller Support

Page 14: Apache Camel - WJax 2008

Camel (Konzepte)

CamelContext Component Endpoint Message/Exchange Processor RouteBuilder/Java DSL

Page 15: Apache Camel - WJax 2008

CamelContext

Spring:<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">

</camelContext>

Pure Java:CamelContext camel = new DefaultCamelContext();

camelContext.start();

Page 16: Apache Camel - WJax 2008

Component

Spring:<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">

<property name="connectionFactory">

<bean class="org.apache.activemq.ActiveMQConnectionFactory">

<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>

</bean>

</property>

</bean>

Pure Java:Component mailComponent = new org.apache.camel.component.mail.MailComponent();

Page 17: Apache Camel - WJax 2008

Endpoint

Spring:<cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9003/CamelContext/RouterPort"

serviceClass="org.apache.hello_world_soap_http.GreeterImpl"/>

URI:

cxf:bean:routerEndpoint

Pure Java:Endpoint endpoint = component.createEndpoint("log:com.mycompany.part2");

URI:

log:com.mycompany.part2

Page 18: Apache Camel - WJax 2008

Message/Exchange/Processor

Pure Java:Exchange exchange = endpoint.createExchange();

exchange.getIn().setBody(name);

public class MyProcessor implements Processor {

public void process(Exchange exchange) throws Exception {

// do something...

}

}

Processor myProcessor = new MyProcessor();

Page 19: Apache Camel - WJax 2008

RouteBuilder

Spring:<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">

<route>

<from uri="activemq:Input"/>

<bean ref="myBeanName" method="doTransform"/>

<to uri="activemq:Output"/>

</route>

</camelContext>

Page 20: Apache Camel - WJax 2008

RouteBuilder (Java DSL)

Pure Java:from("activemq:Input").beanRef("myBeanName", "doTransform").to("activemq:Output");

RouteBuilder builder = new RouteBuilder() {

public void configure() {

from("queue:a").filter(header("foo").isEqualTo("bar")).to("queue:b");

from("queue:c").choice()

.when(header("foo").isEqualTo("bar")).to("queue:d")

.when(header("foo").isEqualTo("cheese")).to("queue:e")

.otherwise().to("queue:f");

}

};

myCamelContext.addRoutes(builder);

Page 21: Apache Camel - WJax 2008

RouteBuilder (Scala DSL beta)

class MyRouteBuilder extends RouteBuilder {

"direct:a" --> "mock:a"

"direct:b" to "mock:b"

}

Page 22: Apache Camel - WJax 2008

VeS (Splitter)

<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">

<route>

<from uri="cxf:requests"/>

<splitter>

<xpath>/login | /account</xpath>

<to uri="direct:splitrequest"/>

</splitter>

</route>

</camelContext>

Page 23: Apache Camel - WJax 2008

VeS (Router)

RouteBuilder builder = new RouteBuilder() {

public void configure() {

from("direct:splitrequest").choice().when(xpath("/login")).to("seda:loginData")

.when(xpath("/account")).to("seda:accountData");

}

};

Page 24: Apache Camel - WJax 2008

VeS (2. Router)

RouteBuilder builder = new RouteBuilder() {

public void configure() {

from("seda:accountData").choice().when(groovy(“request.account.id =~ /A.*/”))

.to("seda:oldAccountData")

.when(groovy("request.account.id =~ /B.*/")).to("seda:newAccountData");

}

};

Page 25: Apache Camel - WJax 2008

VeS (Transformation)

<route>

<from uri="seda:loginData"/>

<bean ref="loginBackend" method="doTransform"/>

<to uri="seda:loginBackend"/>

</route>

Page 26: Apache Camel - WJax 2008

Expression Languages

from("queue:a").filter(header("foo").isEqualTo("bar")header("foo").isEqualTo("bar")).to("queue:b");

Expression Language filter().el("${in.headers['My Header'] == 'bar'}")

OGNL filter().ognl("request.headers.foo = 'bar'")

Javascript filter().javaScript("request.headers.get('user') == 'admin'")

Groovy filter().groovy("request.lineItems.any { i -> i.value > 100 }")

Python filter().python("request.headers['user'] == 'admin'")

Ruby filter().ruby("$request.headers['user'] == 'admin'")

Xpath filter().xpath("//foo")

Xquery filter().xquery("//foo")

Scripting languages via JSR223

Page 27: Apache Camel - WJax 2008

Components

ActiveMQ (activemq:FOO.BAR) Atom (atom://atomUri) CXF (cxf:bean:cxfEndpoint) Spring events (spring-event://default) File (file://inputdir/?delete=true) Financial Information eXchange

(fix://configurationResource)

Page 28: Apache Camel - WJax 2008

Components

Flatpack (flatpack:fixed:foo.pzmap.xml) FTP

(ftp://camelrider@localhost:21/public/downloads)

HL7 (Health Level 7) HTTP/Jetty JBI (jbi:service:http://foo.bar.org/Service) Java Content Repository

(jcr://user:pass@repository/repo)

Page 29: Apache Camel - WJax 2008

Components

JMS (jms:FOO.BAR) JPA (jpa:account) LDAP (ldap:localhost:1024) Log (log:org.camel.example.Foo) Mail (imap://[email protected]) Mina (mina:tcp://localhost:6200?

textline=true) Mock (mock:foo) RMI (rmi://localhost:1099/foo)

Page 30: Apache Camel - WJax 2008

Components

Seda (seda:start) Smooks (EDI parsing) Test (test:file://data/expectedOutput) Timer (timer://foo?

fixedRate=true&period=60000) Velocity

(velocity:com/acme/MyResponse.vm) Vm (vm:foo) Xmpp (xmpp://fromAlias/toAlias)

Page 31: Apache Camel - WJax 2008

Möglichkeiten

BAM (Wiretap Pattern) Bean Integration Visualisierung Komponenten-

erstellung

Page 32: Apache Camel - WJax 2008

Fazit

Apache Camel ist klein leicht fokussiert modular

Don't get the hump, try Camel today.

Page 33: Apache Camel - WJax 2008

Credits

the camel riders IBM System 360 (CC cote on flickr) the camel's way (CC lovelypetal on flickr)