SlideShare ist ein Scribd-Unternehmen logo
1 von 68
Downloaden Sie, um offline zu lesen
Taking
Apache Camel
 For A Ride
Bruce Snyder
bsnyder@apache.org
7 Nov 2008
New Orleans, Louisiana
Protocol Integration
    is Common
Data Format Integration
      is Common
Integration is Messy!
SOA = Spaghetti Oriented
      Architecture
Options For Integration
1             2




       3
Too Many Choices!
The Easiest Solution - Apache
           Camel




      http://activemq.apache.org/camel/
What is
Apache Camel?
Enterprise Integration
      Patterns




http://enterpriseintegrationpatterns.com/
Message Routing
Patterns
History of Apache Camel
Camel Components




http://activemq.apache.org/camel/components.html
Camel Components
Simple Routing
More Simple Routing
Pipeline Routing
Multicast Routing
Multicast-to-Many
 Pipeline Routes
Language Support
For Message Processing
 •   BeanShell    •   JSP EL
 •   Javascript   •   OGNL
 •   Groovy       •   SQL
 •   Python       •   XPath
 •   PHP          •   XQuery
 •   Ruby
Getting Started -
          The Camel Context

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




<camelContext
  xmlns=quot;http://activemq.apache.org/camel/schema/springquot;>
  <package>com.acme.quotes</package>
</camelContext>
Pattern
Examples
Patterns
Content Based Router




  RouteBuilder builder = new RouteBuilder() {
public void configure() {
  from(quot;seda:aquot;).choice().when(header(quot;fooquot;)
     .isEqualTo(quot;barquot;)).to(quot;seda:bquot;)
       .when(header(quot;fooquot;).isEqualTo(quot;cheesequot;))
         .to(quot;seda:cquot;).otherwise().to(quot;seda:dquot;);
       }
  };
Content Based Router
<camelContext
  xmlns=quot;http://activemq.apache.org/camel/schema/springquot;>
  <route>
    <from uri=quot;activemq:NewOrdersquot;/>
    <choice>
      <when>
        <xpath>/order/product = 'widget'</xpath>
        <to uri=quot;activemq:Orders.Widgetsquot;/>
      </when>
      <when>
        <xpath>/order/product = 'gadget'</xpath>
        <to uri=quot;activemq:Orders.Gadgetsquot;/>
      </when>
      <otherwise>
        <to uri=quot;activemq:Orders.Badquot;/>
      </otherwise>
    </choice>
  </route>
</camelContext>
Message Filter




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
        from(quot;activemq:topic:Quotes).
            filter().xpath(quot;/quote/product = ‘widget’quot;).
                to(quot;mqseries:WidgetQuotesquot;);
  }
}
Message Filter
<camelContext
  xmlns=quot;http://activemq.apache.org/camel/schema/springquot;>
    <route>
      <from uri=quot;activemq:topic:Quotesquot;/>
      <filter>
        <xpath>/quote/product = ‘widget’</xpath>
        <to uri=quot;mqseries:WidgetQuotesquot;/>
      </filter>
    </route>
  </camelContext>
Splitter




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;file://ordersquot;).
        splitter(body().tokenize(quot;nquot;)).
          to(quot;activemq:Order.Itemsquot;);
    }
  }
Splitter Using XQuery

public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;file://ordersquot;).
        splitter().xquery(quot;/order/itemsquot;).
          to(quot;activemq:Order.Itemsquot;);
    }
  }
Aggregator



public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;activemq:Inventory.Itemsquot;).
      aggregator(header(quot;symbolquot;).isEqualTo(quot;IBMquot;).
        to(quot;activemq:Inventory.Orderquot;);
  }
}
Message Translator




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;file://incoming”).
        to(quot;xslt:com/acme/mytransform.xslquot;).
          to(quot;http://outgoing.com/fooquot;);
    }
  }
Resequencer




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;direct:a”).
        resequencer(header(quot;customerRankquot;)).
          to(quot;seda:bquot;);
    }
  }
Routing Slip




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;direct:a”).routingSlip();
    }
  }
Throttler

public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;seda:a”).
        throttler(3).timePeriodMillis(30000).
          to(quot;seda:bquot;);
    }
  }
Delayer
public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;seda:a”).
        delayer(header(quot;JMSTimestampquot;, 3000).
          to(quot;seda:bquot;);
    }
  }
Load Balancer
    public class MyRouteBuilder extends RouteBuilder {
        public void configure() {
            from(quot;file:/path/to/filequot;).
            loadBalance().roundRobin().
                to(quot;seda:aquot;, quot;seda:bquot;, quot;seda:cquot;);
        }
   }



  Policy                                   Description
Round Robin    Balance the exchange load across the available endpoints

 Random        Randomly choose an endpoint to send the exchange

  Sticky       Sticky load balancing of exchanges using an expression

   Topic       Send exchange to all endpoints (like a JMS topic)
Multicast

public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;direct:aquot;).
      multicast().
      to(quot;direct:x?x=y&amp;1=2quot;, quot;direct:yquot;, quot;direct:zquot;);
    }
  }
Demo
More
Patterns
Wire Tap




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;direct:aquot;).
      to(quot;log:com.mycompany.messages?level=infoquot;).
      to(quot;mock:fooquot;);
    }
  }
Content Enricher




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;activemq:My.Queuequot;).
      to(quot;velocity:com/acme/MyResponse.vmquot;).
      to(quot;activemq:Another.Queuequot;);
    }
  }
More Content Enricher




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;activemq:My.Queuequot;).
      beanRef(quot;myBeanNamequot;, quot;myMethodNamequot;).
      to(quot;activemq:Another.Queuequot;);
    }
  }
Content Filter




 public class MyRouteBuilder extends RouteBuilder {
      public void configure() {
        from(quot;direct:startquot;).process(new Processor() {
            public void process(Exchange exchange) {
                Message in = exchange.getIn();
                in.setBody(in.getBody(String.class) + quot; World!quot;);
            }
        }).to(quot;mock:resultquot;);
    }
}
Combine Patterns

public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;seda:a”).
        resequencer(header(quot;JMSGroupSeqquot;)).
        delayer(3000).
          to(quot;mock:xquot;);
    }
  }
Configure Error Handling

Global Error Handler:

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        errorHandler(deadLetterChannel(quot;file:errorsquot;));
        from(quot;bean:fooquot;).to(quot;seda:bquot;);
    }
};
Configure Error Handling


Local Error Handler:
RouteBuilder builder = new RouteBuilder() {
    public void configure() {
      from(quot;seda:aquot;).
        errorHandler(loggingErrorHandler(quot;FOO.BARquot;)).
        to(quot;seda:bquot;);

         from(quot;seda:bquot;).to(quot;seda:cquot;);
     }
};
Configure Exception Policies

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        exception(IOException.class)
          .initialRedeliveryDelay(5000L)
          .maximumRedeliveries(3)
          .maximumRedeliveryDelay(30000L)
          .backOffMultiplier(1.0)
          .useExponentialBackOff()
          .setHeader(MESSAGE_INFO, constant(quot;Damned IOException!quot;))
          .to(quot;activemq:errorsquot;);

         from(quot;seda:aquot;).to(quot;seda:bquot;);
     }
};
Beans
Make Context Discover Beans

  package com.mycompany.beans;

  public class MyBean {

      public void someMethod(String name) {
        ...
      }
  }


<camelContext
  xmlns=quot;http://activemq.apache.org/camel/schema/springquot;>
  <package>com.mycompany.beans</package>
</camelContext>
Bean as a Message Translator

  public class MyRouteBuilder extends RouteBuilder {
      public void configure() {
        from(quot;activemq:Incoming”).
          beanRef(quot;myBeanquot;).
            to(quot;activemq:Outgoingquot;);
      }
    }
Bean as a
          Message Translator

*With Method Name
public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
        from(quot;activemq:Incoming”).
          beanRef(quot;myBeanquot;, quot;someMethodquot;).
            to(quot;activemq:Outgoingquot;);
    }
}
Binding Beans to
     Camel Endpoints

public class Foo {

    @MessageDriven(uri=quot;activemq:cheesequot;)
    public void onCheese(String name) {
      ...
    }
}
Binding Method Arguments

  public class Foo {

      public void onCheese(
        @XPath(quot;/foo/barquot;) String name,
        @Header(quot;JMSCorrelationIDquot;) String id) {
        ...
      }
  }
Injecting Endpoints
           Into Beans

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

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

@Converter
public class IOConverter {

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

 public class MyRouteBuilder extends RouteBuilder {
      public void configure() {
        from(quot;direct:startquot;).process(new Processor() {
            public void process(Exchange exchange) {
                Message in = exchange.getIn();
                in.setBody(in.getBody(String.class) + quot; World!quot;);
            }
        }).to(quot;mock:resultquot;);
    }
}


             Support for the following types:
             • File
             • String
             • byte[] and ByteBuffer
             • InputStream and OutputStream
             • Reader and Writer
             • Document and Source
Message Mapper
Message Translator




public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;file://incoming”).
        to(quot;xslt:com/acme/mytransform.xslquot;).
          to(quot;http://outgoing.com/fooquot;);
    }
  }
Another
      Message Translator

public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
      from(quot;activemq:FOO.TEST”).
      transform(body().append(getDynamicText())).
        to(quot;http://outgoing.com/fooquot;);
  }
}
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 query of the message body
        ActivityBuilder purchaseOrder = activity(quot;activemq:PurchaseOrdersquot;)
                .correlate(xpath(quot;/purchaseOrder/@idquot;).stringResult());

        ActivityBuilder invoice = activity(quot;activemq:Invoicesquot;)
                .correlate(xpath(quot;/invoice/@purchaseOrderIdquot;).stringResult());

        // now lets add some BAM rules
        invoice.starts().after(purchaseOrder.completes())
                .expectWithin(seconds(1))
                .errorIfOver(seconds(2)).to(quot;activemq:FailedProcessesquot;);
    }
}
Complex Routing is Easier
          from(“http://localhost:8080/requests/”).
              tryBlock().
                  to(“activemq:queue:requests”).
                  setOutBody(constant(“<ack/>”)).
              handle(Throwable.class).
                  setFaultBody(constant(“<nack/>”));

          from((“activemq:queue:requests?transacted=true”).
              process(requestTransformer).
              to(“http://host:8080/Request”).
              filter(xpath(“//nack”)).
              process(nackTransformer).
              to(“jdbc:store”);

          from(“http://localhost:8080/responses/”).
              tryBlock().
                  to(“activemq:queue:responses”).
                  setOutBody(constant(“<ack/>”)).
              handle(Throwable.class).
                  setFaultBody(constant(“<nack/>”));

          from(“activemq:queue:responses?transacted=true”).
              process(responseTransformer).
              to(“jdbc:store”);

          from(“http://localhost:8080/pull/”).
              to(“jdbc:load”);
Finally, the Camel Truck!
Ride the Camel!


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

Weitere ähnliche Inhalte

Was ist angesagt?

RESTfull with RestKit
RESTfull with RestKitRESTfull with RestKit
RESTfull with RestKit
Taras Kalapun
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
Morgan Cheng
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE
 

Was ist angesagt? (19)

Map kit light
Map kit lightMap kit light
Map kit light
 
RESTfull with RestKit
RESTfull with RestKitRESTfull with RestKit
RESTfull with RestKit
 
Net/http and the http.handler interface
Net/http and the http.handler interfaceNet/http and the http.handler interface
Net/http and the http.handler interface
 
From Node to Go
From Node to GoFrom Node to Go
From Node to Go
 
Build Lightweight Web Module
Build Lightweight Web ModuleBuild Lightweight Web Module
Build Lightweight Web Module
 
Win32 Perl Wmi
Win32 Perl WmiWin32 Perl Wmi
Win32 Perl Wmi
 
ReactiveCocoa in Practice
ReactiveCocoa in PracticeReactiveCocoa in Practice
ReactiveCocoa in Practice
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
Gmaps Railscamp2008
Gmaps Railscamp2008Gmaps Railscamp2008
Gmaps Railscamp2008
 
Clojutre Real Life (2012 ClojuTRE Retro Edition)
Clojutre Real Life (2012 ClojuTRE Retro Edition)Clojutre Real Life (2012 ClojuTRE Retro Edition)
Clojutre Real Life (2012 ClojuTRE Retro Edition)
 
Protocol-Oriented Networking
Protocol-Oriented NetworkingProtocol-Oriented Networking
Protocol-Oriented Networking
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 
Little Big Ruby
Little Big RubyLittle Big Ruby
Little Big Ruby
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Matteo Collina | Take your HTTP server to Ludicrous Speed | Codmeotion Madrid...
Matteo Collina | Take your HTTP server to Ludicrous Speed | Codmeotion Madrid...Matteo Collina | Take your HTTP server to Ludicrous Speed | Codmeotion Madrid...
Matteo Collina | Take your HTTP server to Ludicrous Speed | Codmeotion Madrid...
 
Relaxing With CouchDB
Relaxing With CouchDBRelaxing With CouchDB
Relaxing With CouchDB
 
Finch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with FinagleFinch.io - Purely Functional REST API with Finagle
Finch.io - Purely Functional REST API with Finagle
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 

Ähnlich wie Taking Apache Camel For A Ride

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
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
phanleson
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
Using Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel JockeyUsing Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel Jockey
Bruce Snyder
 

Ähnlich wie Taking Apache Camel For A Ride (20)

Riding Apache Camel
Riding Apache CamelRiding Apache Camel
Riding Apache Camel
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A Ride
 
Aimaf
AimafAimaf
Aimaf
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a Ride
 
30 5 Database Jdbc
30 5 Database Jdbc30 5 Database Jdbc
30 5 Database Jdbc
 
My java file
My java fileMy java file
My java file
 
Orbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case StudyOrbitz and Spring Webflow Case Study
Orbitz and Spring Webflow Case Study
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
如何透過 Go-kit 快速搭建微服務架構應用程式實戰如何透過 Go-kit 快速搭建微服務架構應用程式實戰
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
 
Using Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel JockeyUsing Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel Jockey
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기[245] presto 내부구조 파헤치기
[245] presto 내부구조 파헤치기
 
Myfacesplanet
MyfacesplanetMyfacesplanet
Myfacesplanet
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Intro
IntroIntro
Intro
 
What's Coming in Spring 3.0
What's Coming in Spring 3.0What's Coming in Spring 3.0
What's Coming in Spring 3.0
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 

Mehr von Bruce Snyder

Beyond Horizontal Scalability: Concurrency and Messaging Using Spring
Beyond Horizontal Scalability: Concurrency and Messaging Using SpringBeyond Horizontal Scalability: Concurrency and Messaging Using Spring
Beyond Horizontal Scalability: Concurrency and Messaging Using Spring
Bruce Snyder
 
Enterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMSEnterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMS
Bruce Snyder
 
Styles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringStyles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using Spring
Bruce Snyder
 
ActiveMQ In Action
ActiveMQ In ActionActiveMQ In Action
ActiveMQ In Action
Bruce Snyder
 
ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011
Bruce Snyder
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMix
Bruce Snyder
 
Service-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixService-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMix
Bruce Snyder
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQ
Bruce Snyder
 
Enterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSEnterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMS
Bruce Snyder
 

Mehr von Bruce Snyder (12)

Beyond Horizontal Scalability: Concurrency and Messaging Using Spring
Beyond Horizontal Scalability: Concurrency and Messaging Using SpringBeyond Horizontal Scalability: Concurrency and Messaging Using Spring
Beyond Horizontal Scalability: Concurrency and Messaging Using Spring
 
Enterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMSEnterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMS
 
Styles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringStyles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using Spring
 
ActiveMQ In Action
ActiveMQ In ActionActiveMQ In Action
ActiveMQ In Action
 
ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMix
 
Service-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixService-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMix
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQ
 
Enterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSEnterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMS
 
EIP In Practice
EIP In PracticeEIP In Practice
EIP In Practice
 
Messaging With ActiveMQ
Messaging With ActiveMQMessaging With ActiveMQ
Messaging With ActiveMQ
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
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...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Taking Apache Camel For A Ride

  • 1. Taking Apache Camel For A Ride Bruce Snyder bsnyder@apache.org 7 Nov 2008 New Orleans, Louisiana
  • 5.
  • 6. SOA = Spaghetti Oriented Architecture
  • 7.
  • 10. The Easiest Solution - Apache Camel http://activemq.apache.org/camel/
  • 12. Enterprise Integration Patterns http://enterpriseintegrationpatterns.com/
  • 23. Language Support For Message Processing • BeanShell • JSP EL • Javascript • OGNL • Groovy • SQL • Python • XPath • PHP • XQuery • Ruby
  • 24. Getting Started - The Camel Context CamelContext context = new DefaultCamelContext(); context.addRoutes(new MyRouteBuilder()); context.start(); <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <package>com.acme.quotes</package> </camelContext>
  • 27. Content Based Router RouteBuilder builder = new RouteBuilder() { public void configure() { from(quot;seda:aquot;).choice().when(header(quot;fooquot;) .isEqualTo(quot;barquot;)).to(quot;seda:bquot;) .when(header(quot;fooquot;).isEqualTo(quot;cheesequot;)) .to(quot;seda:cquot;).otherwise().to(quot;seda:dquot;); } };
  • 28. Content Based Router <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <route> <from uri=quot;activemq:NewOrdersquot;/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri=quot;activemq:Orders.Widgetsquot;/> </when> <when> <xpath>/order/product = 'gadget'</xpath> <to uri=quot;activemq:Orders.Gadgetsquot;/> </when> <otherwise> <to uri=quot;activemq:Orders.Badquot;/> </otherwise> </choice> </route> </camelContext>
  • 29. Message Filter public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:topic:Quotes). filter().xpath(quot;/quote/product = ‘widget’quot;). to(quot;mqseries:WidgetQuotesquot;); } }
  • 30. Message Filter <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <route> <from uri=quot;activemq:topic:Quotesquot;/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri=quot;mqseries:WidgetQuotesquot;/> </filter> </route> </camelContext>
  • 31. Splitter public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file://ordersquot;). splitter(body().tokenize(quot;nquot;)). to(quot;activemq:Order.Itemsquot;); } }
  • 32. Splitter Using XQuery public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file://ordersquot;). splitter().xquery(quot;/order/itemsquot;). to(quot;activemq:Order.Itemsquot;); } }
  • 33. Aggregator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:Inventory.Itemsquot;). aggregator(header(quot;symbolquot;).isEqualTo(quot;IBMquot;). to(quot;activemq:Inventory.Orderquot;); } }
  • 34. Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file://incoming”). to(quot;xslt:com/acme/mytransform.xslquot;). to(quot;http://outgoing.com/fooquot;); } }
  • 35. Resequencer public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;direct:a”). resequencer(header(quot;customerRankquot;)). to(quot;seda:bquot;); } }
  • 36. Routing Slip public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;direct:a”).routingSlip(); } }
  • 37. Throttler public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;seda:a”). throttler(3).timePeriodMillis(30000). to(quot;seda:bquot;); } }
  • 38. Delayer public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;seda:a”). delayer(header(quot;JMSTimestampquot;, 3000). to(quot;seda:bquot;); } }
  • 39. Load Balancer public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file:/path/to/filequot;). loadBalance().roundRobin(). to(quot;seda:aquot;, quot;seda:bquot;, quot;seda:cquot;); } } Policy Description Round Robin Balance the exchange load across the available endpoints Random Randomly choose an endpoint to send the exchange Sticky Sticky load balancing of exchanges using an expression Topic Send exchange to all endpoints (like a JMS topic)
  • 40. Multicast public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;direct:aquot;). multicast(). to(quot;direct:x?x=y&amp;1=2quot;, quot;direct:yquot;, quot;direct:zquot;); } }
  • 41. Demo
  • 43. Wire Tap public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;direct:aquot;). to(quot;log:com.mycompany.messages?level=infoquot;). to(quot;mock:fooquot;); } }
  • 44. Content Enricher public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:My.Queuequot;). to(quot;velocity:com/acme/MyResponse.vmquot;). to(quot;activemq:Another.Queuequot;); } }
  • 45. More Content Enricher public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:My.Queuequot;). beanRef(quot;myBeanNamequot;, quot;myMethodNamequot;). to(quot;activemq:Another.Queuequot;); } }
  • 46. Content Filter public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;direct:startquot;).process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + quot; World!quot;); } }).to(quot;mock:resultquot;); } }
  • 47. Combine Patterns public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;seda:a”). resequencer(header(quot;JMSGroupSeqquot;)). delayer(3000). to(quot;mock:xquot;); } }
  • 48. Configure Error Handling Global Error Handler: RouteBuilder builder = new RouteBuilder() { public void configure() { errorHandler(deadLetterChannel(quot;file:errorsquot;)); from(quot;bean:fooquot;).to(quot;seda:bquot;); } };
  • 49. Configure Error Handling Local Error Handler: RouteBuilder builder = new RouteBuilder() { public void configure() { from(quot;seda:aquot;). errorHandler(loggingErrorHandler(quot;FOO.BARquot;)). to(quot;seda:bquot;); from(quot;seda:bquot;).to(quot;seda:cquot;); } };
  • 50. Configure Exception Policies RouteBuilder builder = new RouteBuilder() { public void configure() { exception(IOException.class) .initialRedeliveryDelay(5000L) .maximumRedeliveries(3) .maximumRedeliveryDelay(30000L) .backOffMultiplier(1.0) .useExponentialBackOff() .setHeader(MESSAGE_INFO, constant(quot;Damned IOException!quot;)) .to(quot;activemq:errorsquot;); from(quot;seda:aquot;).to(quot;seda:bquot;); } };
  • 51. Beans
  • 52. Make Context Discover Beans package com.mycompany.beans; public class MyBean { public void someMethod(String name) { ... } } <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <package>com.mycompany.beans</package> </camelContext>
  • 53. Bean as a Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:Incoming”). beanRef(quot;myBeanquot;). to(quot;activemq:Outgoingquot;); } }
  • 54. Bean as a Message Translator *With Method Name public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:Incoming”). beanRef(quot;myBeanquot;, quot;someMethodquot;). to(quot;activemq:Outgoingquot;); } }
  • 55. Binding Beans to Camel Endpoints public class Foo { @MessageDriven(uri=quot;activemq:cheesequot;) public void onCheese(String name) { ... } }
  • 56. Binding Method Arguments public class Foo { public void onCheese( @XPath(quot;/foo/barquot;) String name, @Header(quot;JMSCorrelationIDquot;) String id) { ... } }
  • 57. Injecting Endpoints Into Beans public class Foo { @EndpointInject(uri=quot;activemq:foo.barquot;) ProducerTemplate producer; public void doSomething() { if (whatever) { producer.sendBody(quot;<hello>world!</hello>quot;); } } }
  • 59. Type Conversion @Converter public class IOConverter { @Converter public static InputStream toInputStream(File file) throws FileNotFoundException { return new BufferedInputStream( new FileInputStream(file)); } }
  • 60. Type Convertors public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;direct:startquot;).process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + quot; World!quot;); } }).to(quot;mock:resultquot;); } } Support for the following types: • File • String • byte[] and ByteBuffer • InputStream and OutputStream • Reader and Writer • Document and Source
  • 62. Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file://incoming”). to(quot;xslt:com/acme/mytransform.xslquot;). to(quot;http://outgoing.com/fooquot;); } }
  • 63. Another Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:FOO.TEST”). transform(body().append(getDynamicText())). to(quot;http://outgoing.com/fooquot;); } }
  • 65. Business Activity Monitoring (BAM) public class MyActivities extends ProcessBuilder { public void configure() throws Exception { // lets define some activities, correlating on an // XPath query of the message body ActivityBuilder purchaseOrder = activity(quot;activemq:PurchaseOrdersquot;) .correlate(xpath(quot;/purchaseOrder/@idquot;).stringResult()); ActivityBuilder invoice = activity(quot;activemq:Invoicesquot;) .correlate(xpath(quot;/invoice/@purchaseOrderIdquot;).stringResult()); // now lets add some BAM rules invoice.starts().after(purchaseOrder.completes()) .expectWithin(seconds(1)) .errorIfOver(seconds(2)).to(quot;activemq:FailedProcessesquot;); } }
  • 66. Complex Routing is Easier from(“http://localhost:8080/requests/”). tryBlock(). to(“activemq:queue:requests”). setOutBody(constant(“<ack/>”)). handle(Throwable.class). setFaultBody(constant(“<nack/>”)); from((“activemq:queue:requests?transacted=true”). process(requestTransformer). to(“http://host:8080/Request”). filter(xpath(“//nack”)). process(nackTransformer). to(“jdbc:store”); from(“http://localhost:8080/responses/”). tryBlock(). to(“activemq:queue:responses”). setOutBody(constant(“<ack/>”)). handle(Throwable.class). setFaultBody(constant(“<nack/>”)); from(“activemq:queue:responses?transacted=true”). process(responseTransformer). to(“jdbc:store”); from(“http://localhost:8080/pull/”). to(“jdbc:load”);
  • 68. Ride the Camel! http://activemq.apache.org/camel/