SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
Easy Enterprise Integration Patterns
                  with Apache Camel,
               ActiveMQ and ServiceMix




                           James Strachan
                   http://macstrac.blogspot.com/




http://open.iona.com/
What are Enterprise Integration Patterns?
Book by Gregor & Bobby!
A selection of some of the patterns...
What is Camel?
Why?
Aims of Camel

    to make integration as simple as it can possibly be
What is Camel?
           http://activemq.apache.org/camel/
What is Camel?




Spring based Enterprise Integration Patterns

http://activemq.apache.org/camel/enterprise-integration-patterns.html
A selection of some of the patterns...
Lets look at a pattern!
Message Filter
Message Filter : XML


   <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 : Spring XML

 <?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://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 : XML


   <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>
Expressions & Predicates


             BeanShell      PHP
                 EL        Python
               Groovy      Ruby
             JavaScript     SQL
              JSR 223      XPath
               OGNL        XQuery
URIs, Endpoints and Components

 http://activemq.apache.org/camel/components.html

   activemq        ibatis     mail           rmi            udp

activemq.journal   imap       mina           rnc          validation

     bean           irc      mock            rng           velocity

      cxf          jdbc       msv            seda            vm

     direct        jetty    multicast        sftp          xmpp

     event          jbi       pojo          smtp           xquery

      file          jms        pop       string-template      xslt

      ftp           jpa      quartz          timer        webdav

      http          log      queue           tcp
Message Filter : XML


   <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 : Java




from("activemq:topic:Quotes).
  filter().xpath("/quote/product = ‘widget’").
    to("mqseries:WidgetQuotes");
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");
    }
}
Create CamelContext in Java




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




<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
  <package>com.acme.quotes</package>
</camelContext>
More Patterns!
Content Based Router
Content Based Router

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



     from("file://orders").
       splitter(body().tokenize("n")).
         to("activemq:Order.Items");
Splitter using XQuery



   from("file://orders").
     splitter().xquery("/order/items").
       to("activemq:Order.Items");
Aggregator
Aggregator




    from("activemq:Inventory.Items").
      aggregator().xpath("/order/@id").
      to("activemq:Inventory.Order");
Message Translator
Message Translator




from("file://incoming”).
  to("xslt:com/acme/mytransform.xsl").
    to("http://outgoing.com/foo");
Quick recap
Beans
Bean as a Message Translator




from("activemq:Incoming”).
  beanRef("myBeanName").
    to("activemq:Outgoing");
Bean




public class Foo {

    public void someMethod(String name) {
      ...
    }
}
Bean as a Message Translator with method name




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

package com.acme.foo.converters;

import org.apache.camel.Converter;
import java.io.*;

@Converter
public class IOConverter {

    @Converter
    public static InputStream toInputStream(File file) throws FileNotFoundException {
        return new BufferedInputStream(new FileInputStream(file));
    }
}




# META-INF/services/org/apache/camel/TypeConverter

com.acme.foo.converters
Binding Beans to Camel Endpoints



 public class Foo {

     @MessageDriven(uri="activemq:cheese")
     public void onCheese(String name) {
       ...
     }
 }
Binding Method Arguments


 public class Foo {

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

                     for more annotations see
     http://activemq.apache.org/camel/bean-integration.html
Injecting endpoints into beans


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

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




 <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
   <proxy id="sayService" serviceUrl="activemq:MyService"
     serviceInterface="com.acme.MyServiceInterface"/>
 </camelContext>
Spring Remoting - Server Side



 <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
   <export id="sayService" uri="activemq:MyService" serviceRef="sayImpl"
     serviceInterface="com.acme.MyServiceInterface"/>
 </camelContext>

 <bean id="sayImpl" class="com.acme.MyServiceImpl"/>
Dependency Injection

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

<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>
Data Format




from("activemq:QueueWithJavaObjects).
  marshal().jaxb().
    to("mqseries:QueueWithXmlMessages");
Business Activity Monitoring (BAM)
Business Activity Monitoring (BAM)

public class MyActivities extends ProcessBuilder {

     public void configure() throws Exception {

         // lets define some activities, correlating on an XPath on the message bodies
         ActivityBuilder purchaseOrder = activity("activemq:PurchaseOrders")
                 .correlate(xpath("/purchaseOrder/@id").stringResult());

         ActivityBuilder invoice = activity("activemq:Invoices")
                 .correlate(xpath("/invoice/@purchaseOrderId").stringResult());

         // now lets add some BAM rules
         invoice.starts().after(purchaseOrder.completes())
                 .expectWithin(seconds(1))
                 .errorIfOver(seconds(2)).to("activemq:FailedProcesses");
     }
}
Riding the camel
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
Camel Riding from Java




•/META-INF/spring/camelContext.xml
•set the CLASSPATH
•java org.apache.camel.spring.Main
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
Maven Plugin Site Report
Where do I get more info?
                please do take Camel for a ride!


             http://activemq.apache.org/camel/

                    don’t get the hump! :-)
Questions?
James Strachan




                             blog


                 http://macstrac.blogspot.com/
Camel v Mule




• A Camel can carry 4 times as much load as other beasts of burden!


 http://activemq.apache.org/camel/why-the-name-camel.html
Camel v Mule

•Camel provides a higher level abstraction for
 EIP; making it simpler & easier & less XML

•Awesome integration with JMS + ActiveMQ
 (client and broker), JBI + ServiceMix and
 JAX-WS + CXF

•great testing with Camel’s Mock Endpoint

•Business Activity Monitoring framework
Where do I get more info?
                please do take Camel for a ride!


             http://activemq.apache.org/camel/

                    don’t get the hump! :-)

Contenu connexe

Tendances

System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
krasserm
 
Using Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityUsing Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivity
Claus Ibsen
 

Tendances (20)

Integration made easy with Apache Camel
Integration made easy with Apache CamelIntegration made easy with Apache Camel
Integration made easy with Apache Camel
 
Developing Java based microservices ready for the world of containers
Developing Java based microservices ready for the world of containersDeveloping Java based microservices ready for the world of containers
Developing Java based microservices ready for the world of containers
 
Getting Started with Apache Camel at DevNation 2014
Getting Started with Apache Camel at DevNation 2014Getting Started with Apache Camel at DevNation 2014
Getting Started with Apache Camel at DevNation 2014
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and Groovy
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - Copenhagen
 
Using Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivityUsing Apache Camel connectors for external connectivity
Using Apache Camel connectors for external connectivity
 
State of integration with Apache Camel (ApacheCon 2019)
State of integration with Apache Camel (ApacheCon 2019)State of integration with Apache Camel (ApacheCon 2019)
State of integration with Apache Camel (ApacheCon 2019)
 
Apache Camel K - Fredericia
Apache Camel K - FredericiaApache Camel K - Fredericia
Apache Camel K - Fredericia
 
Getting Started with Apache Camel - Devconf Conference - February 2013
Getting Started with Apache Camel - Devconf Conference - February 2013Getting Started with Apache Camel - Devconf Conference - February 2013
Getting Started with Apache Camel - Devconf Conference - February 2013
 
I can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and SpringI can't believe it's not a queue: Kafka and Spring
I can't believe it's not a queue: Kafka and Spring
 
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebean
 
Java Play Restful JPA
Java Play Restful JPAJava Play Restful JPA
Java Play Restful JPA
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 
Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Rails Performance
Rails PerformanceRails Performance
Rails Performance
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 

En vedette

Employing Enterprise Application Integration (EAI)
Employing Enterprise Application Integration (EAI)Employing Enterprise Application Integration (EAI)
Employing Enterprise Application Integration (EAI)
elliando dias
 
Patterns for Enterprise Integration Success
Patterns for Enterprise Integration Success Patterns for Enterprise Integration Success
Patterns for Enterprise Integration Success
WSO2
 
Topic3 Enterprise Application Integration
Topic3 Enterprise Application IntegrationTopic3 Enterprise Application Integration
Topic3 Enterprise Application Integration
sanjoysanyal
 

En vedette (17)

Smart Enterprise Application Integration with Apache Camel
Smart Enterprise Application Integration with Apache Camel Smart Enterprise Application Integration with Apache Camel
Smart Enterprise Application Integration with Apache Camel
 
Scandev / SDC2013 - Spoilt for Choice: Which Integration Framework to use – A...
Scandev / SDC2013 - Spoilt for Choice: Which Integration Framework to use – A...Scandev / SDC2013 - Spoilt for Choice: Which Integration Framework to use – A...
Scandev / SDC2013 - Spoilt for Choice: Which Integration Framework to use – A...
 
Employing Enterprise Application Integration (EAI)
Employing Enterprise Application Integration (EAI)Employing Enterprise Application Integration (EAI)
Employing Enterprise Application Integration (EAI)
 
Enterprise Integration Patterns with Apache Camel
Enterprise Integration Patterns with Apache CamelEnterprise Integration Patterns with Apache Camel
Enterprise Integration Patterns with Apache Camel
 
TS 4839 - Enterprise Integration Patterns in Practice
TS 4839 - Enterprise Integration Patterns in PracticeTS 4839 - Enterprise Integration Patterns in Practice
TS 4839 - Enterprise Integration Patterns in Practice
 
Patterns for Enterprise Integration Success
Patterns for Enterprise Integration Success Patterns for Enterprise Integration Success
Patterns for Enterprise Integration Success
 
Enterprise Integration Patterns Revisited (EIP) for the Era of Big Data, Inte...
Enterprise Integration Patterns Revisited (EIP) for the Era of Big Data, Inte...Enterprise Integration Patterns Revisited (EIP) for the Era of Big Data, Inte...
Enterprise Integration Patterns Revisited (EIP) for the Era of Big Data, Inte...
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
Topic3 Enterprise Application Integration
Topic3 Enterprise Application IntegrationTopic3 Enterprise Application Integration
Topic3 Enterprise Application Integration
 
Enterprise Integration Patterns Revisited (again) for the Era of Big Data, In...
Enterprise Integration Patterns Revisited (again) for the Era of Big Data, In...Enterprise Integration Patterns Revisited (again) for the Era of Big Data, In...
Enterprise Integration Patterns Revisited (again) for the Era of Big Data, In...
 
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
 
Dynamic AX : Application Integration Framework
Dynamic AX : Application Integration FrameworkDynamic AX : Application Integration Framework
Dynamic AX : Application Integration Framework
 
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
Enterprise Integration Patterns Revisited (EIP, Apache Camel, Talend ESB)
 
Integration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices ArchitecturesIntegration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices Architectures
 
How to choose the right Integration Framework - Apache Camel (JBoss, Talend),...
How to choose the right Integration Framework - Apache Camel (JBoss, Talend),...How to choose the right Integration Framework - Apache Camel (JBoss, Talend),...
How to choose the right Integration Framework - Apache Camel (JBoss, Talend),...
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
Modern Enterprise integration Strategies
Modern Enterprise integration StrategiesModern Enterprise integration Strategies
Modern Enterprise integration Strategies
 

Similaire à Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix

Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a Ride
Bruce Snyder
 
Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQ
elliando dias
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
Luke Summerfield
 

Similaire à Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix (20)

Riding Apache Camel
Riding Apache CamelRiding Apache Camel
Riding Apache Camel
 
Aimaf
AimafAimaf
Aimaf
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a Ride
 
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
자바 웹 개발 시작하기 (1주차 : 웹 어플리케이션 체험 실습)
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Spine.js
Spine.jsSpine.js
Spine.js
 
Camel as a_glue
Camel as a_glueCamel as a_glue
Camel as a_glue
 
Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQ
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Soap Component
Soap ComponentSoap Component
Soap Component
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012
 
How to use soap component
How to use soap componentHow to use soap component
How to use soap component
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache Sling
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
 
Serverless Java on Kubernetes
Serverless Java on KubernetesServerless Java on Kubernetes
Serverless Java on Kubernetes
 
What's new in jQuery 1.5
What's new in jQuery 1.5What's new in jQuery 1.5
What's new in jQuery 1.5
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 

Plus de elliando dias

Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 

Plus de elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix

  • 1. Easy Enterprise Integration Patterns with Apache Camel, ActiveMQ and ServiceMix James Strachan http://macstrac.blogspot.com/ http://open.iona.com/
  • 2. What are Enterprise Integration Patterns?
  • 3. Book by Gregor & Bobby!
  • 4. A selection of some of the patterns...
  • 7. Aims of Camel to make integration as simple as it can possibly be
  • 8. What is Camel? http://activemq.apache.org/camel/
  • 9. What is Camel? Spring based Enterprise Integration Patterns http://activemq.apache.org/camel/enterprise-integration-patterns.html
  • 10. A selection of some of the patterns...
  • 11. Lets look at a pattern!
  • 13. Message Filter : XML <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>
  • 14. Message Filter : Spring XML <?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://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>
  • 15. Message Filter : XML <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>
  • 16. Expressions & Predicates BeanShell PHP EL Python Groovy Ruby JavaScript SQL JSR 223 XPath OGNL XQuery
  • 17. URIs, Endpoints and Components http://activemq.apache.org/camel/components.html activemq ibatis mail rmi udp activemq.journal imap mina rnc validation bean irc mock rng velocity cxf jdbc msv seda vm direct jetty multicast sftp xmpp event jbi pojo smtp xquery file jms pop string-template xslt ftp jpa quartz timer webdav http log queue tcp
  • 18. Message Filter : XML <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>
  • 19. Message Filter : Java from("activemq:topic:Quotes). filter().xpath("/quote/product = ‘widget’"). to("mqseries:WidgetQuotes");
  • 20. 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"); } }
  • 21. Create CamelContext in Java CamelContext context = new DefaultCamelContext(); context.addRoutes(new MyRouteBuilder()); context.start();
  • 22. Create CamelContext in Spring <camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <package>com.acme.quotes</package> </camelContext>
  • 25. Content Based Router <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>
  • 27. Splitter from("file://orders"). splitter(body().tokenize("n")). to("activemq:Order.Items");
  • 28. Splitter using XQuery from("file://orders"). splitter().xquery("/order/items"). to("activemq:Order.Items");
  • 30. Aggregator from("activemq:Inventory.Items"). aggregator().xpath("/order/@id"). to("activemq:Inventory.Order");
  • 32. Message Translator from("file://incoming”). to("xslt:com/acme/mytransform.xsl"). to("http://outgoing.com/foo");
  • 34. Beans
  • 35. Bean as a Message Translator from("activemq:Incoming”). beanRef("myBeanName"). to("activemq:Outgoing");
  • 36. Bean public class Foo { public void someMethod(String name) { ... } }
  • 37. Bean as a Message Translator with method name from("activemq:Incoming”). beanRef("myBeanName", "someMethod"). to("activemq:Outgoing");
  • 39. Type Conversion package com.acme.foo.converters; import org.apache.camel.Converter; import java.io.*; @Converter public class IOConverter { @Converter public static InputStream toInputStream(File file) throws FileNotFoundException { return new BufferedInputStream(new FileInputStream(file)); } } # META-INF/services/org/apache/camel/TypeConverter com.acme.foo.converters
  • 40. Binding Beans to Camel Endpoints public class Foo { @MessageDriven(uri="activemq:cheese") public void onCheese(String name) { ... } }
  • 41. Binding Method Arguments public class Foo { public void onCheese( @XPath("/foo/bar") String name, @Header("JMSCorrelationID") String id) { ... } } for more annotations see http://activemq.apache.org/camel/bean-integration.html
  • 42. Injecting endpoints into beans public class Foo { @EndpointInject(uri="activemq:foo.bar") ProducerTemplate producer; public void doSomething() { if (whatever) { producer.sendBody("<hello>world!</hello>"); } } }
  • 43. Spring Remoting - Client Side <camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <proxy id="sayService" serviceUrl="activemq:MyService" serviceInterface="com.acme.MyServiceInterface"/> </camelContext>
  • 44. Spring Remoting - Server Side <camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <export id="sayService" uri="activemq:MyService" serviceRef="sayImpl" serviceInterface="com.acme.MyServiceInterface"/> </camelContext> <bean id="sayImpl" class="com.acme.MyServiceImpl"/>
  • 45. Dependency Injection <camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> ... </camelContext> <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>
  • 46. Data Format from("activemq:QueueWithJavaObjects). marshal().jaxb(). to("mqseries:QueueWithXmlMessages");
  • 48. Business Activity Monitoring (BAM) public class MyActivities extends ProcessBuilder { public void configure() throws Exception { // lets define some activities, correlating on an XPath on the message bodies ActivityBuilder purchaseOrder = activity("activemq:PurchaseOrders") .correlate(xpath("/purchaseOrder/@id").stringResult()); ActivityBuilder invoice = activity("activemq:Invoices") .correlate(xpath("/invoice/@purchaseOrderId").stringResult()); // now lets add some BAM rules invoice.starts().after(purchaseOrder.completes()) .expectWithin(seconds(1)) .errorIfOver(seconds(2)).to("activemq:FailedProcesses"); } }
  • 50. 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
  • 51. Camel Riding from Java •/META-INF/spring/camelContext.xml •set the CLASSPATH •java org.apache.camel.spring.Main
  • 52. 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
  • 54. Where do I get more info? please do take Camel for a ride! http://activemq.apache.org/camel/ don’t get the hump! :-)
  • 56. James Strachan blog http://macstrac.blogspot.com/
  • 57. Camel v Mule • A Camel can carry 4 times as much load as other beasts of burden! http://activemq.apache.org/camel/why-the-name-camel.html
  • 58. Camel v Mule •Camel provides a higher level abstraction for EIP; making it simpler & easier & less XML •Awesome integration with JMS + ActiveMQ (client and broker), JBI + ServiceMix and JAX-WS + CXF •great testing with Camel’s Mock Endpoint •Business Activity Monitoring framework
  • 59. Where do I get more info? please do take Camel for a ride! http://activemq.apache.org/camel/ don’t get the hump! :-)