• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
01 apache camel-intro
 

01 apache camel-intro

on

  • 849 views

 

Statistics

Views

Total Views
849
Views on SlideShare
849
Embed Views
0

Actions

Likes
1
Downloads
21
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    01 apache camel-intro 01 apache camel-intro Presentation Transcript

    • REDPILL LINPROSWATCompetence Gathering #1 Apache CamelApril 2011 introductionPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • AgendaBackgroundEIPArchitecture from 10,000 ftEndpoints & componentsProgramming modelHiding the integration API from your codeError handlingType convertersDeploymentPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • BackgroundStarted as a subproject to ActiveMQ Now one of the top Apache projectsImplementation of the EIP patternsFramework for declaring routing logicNOT a fullblown runtime, such as an ESB. … but has the same characteristicsReuses Spring concepts such as Templates, DI, registries, contexts etc.. PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Enterprise Integration Patterns (EIP)”Pipe and filter” stateless flowsThe de facto bible when it comes to the messaging integration styleEIP is the basis for all types of flow-based integration frameworks (i.e. Camel, Spring Integration, Jboss ESB, Mule) PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • ...EIP continuedPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • A Camel EIP example Queue Papers Split on each Route on body Queue Queue lineitem Pencils purchaseOrder File dir /invalidfrom("jms:queue:purchaseOrder?concurrentConsumers=5") .split().xpath("//lineItem") .choice() .when(body().contains("Pen")) .to("jms:queue:Pencils") .when(body().contains("Paper")).to("jms:queue:Papers") .otherwise().to("file:target/messages/invalid");PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • 10,000 ft architectureCamelContext - Runtime "engine", similar to a SpringContextRoutes - Your DSL/XML declared flowsComponents - Physical connectivity factories to Endpoints, i.e to()/from()Processors - Implements the Processor interface (process() method) PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Components and endpoints> 100 components jms:myQueue?concurrentConsumers=5&username=Billy Component Path OptionsSeparate JARsThe usual suspects... File / JMS / RMI / WS / Http / DB+ a lot more SEDA, Direct, MINA, XMPP, WebSockets, Twitter...Components are bound to URI schemes..which are then interpreted as Endpoints PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Message ExchangesContext for messagesExchange ID – Unique idMEP – InOnly/InOut EnumException – Contains eventual runtime exceptionProperties – Meta-Data with a lifecycle of the complete exchangeMessage – In/Out used in processors and request/reply PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Programming model Java "DSL" from("file:data/orders") (chained methods) .split.xpath("//order") .to("jms:queue:order"); Declarative XML <route> (NS support) <from uri="file:data/orders"/> <split> <xpath>//order</xpath> <to uri="jms:queue:order"/> </split> </route> - Scala and Groovy alternatives...PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Adding the routes, Java stylepublic class MyRoutes extends RouteBuilder{ @Override public void configure() throws Exception { from("file:/orders").to("jms:/orders"); from("file:/payments").to("jms/payments"); }}camelContext.addRoutes(new MyRoutes()); PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Adding the routes, Spring / Blueprint style <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="file:/orders"/> <to uri="jms:/orders"/> </route> <route> <from uri="file:/payments"/> <to uri="jms:/orders"/> </route> </camelContext>Bootstraps the context as Spring starts Main, servlet listener, camel included Main class etc PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Loading Java Routes from XMLMixn match between XML/JavaConsistent concept throughout the framework <camelContext xmlns="http://camel.apache.org/schema/spring"> <packageScan> <package>com.rl.routes</package> <excludes>**.*Excluded*</excludes> <includes>**.*</includes> </packageScan> </camelContext>Irrespective of the language choice, the routes will be the same as its only instructions to CamelMeans that cross-functionality such as visualization etc works across the languages PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • ProcessorsSimple way to add custom logic in a routeImplements the Processor interfaceQuick and dirty way, define your own anonymous impl inline from("file:/payments") .process(new Processor(){ public void process(Exchange exchng) throws Exception { //business logic on exchange here } }) .to("jms:payments"); PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Service activator patternInstead of implementing the Processor intfReference service beans instead Flexible, less Camel API smell Camel can guess method based on message type/parameters, annotations or method-ref Can also reference by class type instead of registered beans from("file:/payments") .beanRef("paymentService") .to("jms/payments"); @Service class PaymentService{ public PaymentAck conductPayment(String payment){... PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • The Registrypublic interface Registry { Object lookup(String name); <T> T lookup(String name, Class<T> type); <T> Map<String, T> lookupByType(Class<T> type);} Strategy interface for bean lookups Used internally, i.e for finding a TransactionManager impl As well as from your flows, using beanRef(”myBean”) Impl delegates to SpringContext, CDI BeanManager, Guice, OSGi etc... camelContext.setRegistry(myRegistry) PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Payload type conversion from("file://inbox") .convertBodyTo(String.class, "UTF-8") .to("jms:inbox");Camel often automatically tries to convert message payload to method param based on registered convertersIf not, use .convertBodyTo(clazz) from flow to invoke type converter explicitlyCould be used where default type would not be the best fit I.e. explicitly wanting JMS TextMessage over ByteMessage PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Writing type converters @Converter public final class IOConverter { @Converter public static InputStream toInputStream(URL url) throws IOException { return url.openStream(); } }META-INF/services/org/apache/camel/TypeConverter com.rl.common.typeconverters.IOConverter com.rl.<customer>.typeconverters.MyConverter ....Or in runtime using..:context.getTypeConverterRegistry().addTypeConverter(from, to, converter); PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • CamelProxy – Hiding Camel from clientsSame concept as i.e. Spring RemotingCamel automatically creates proxy implementations of a given interfaceDI-wire your proxy to the client<camelContext xmlns="http://camel.apache.org/schema/spring"> <proxy id="paymentService" serviceInterface="se.rl.IPaymentService" serviceUrl="direct:payments"/> <route> <from uri="direct:payments"/> <to uri="...."/> ...... </route></camelContext><b:bean id="paymentClient" class="se.rl.banking.PaymentClient"> <b:property name="paymentSvc" ref="paymentService"/></b:bean> PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Error handlingThrown exceptions → Exchange.exception Typically technical exceptionsCamel Error handling by default only kicks in when exchange.getException() != nullError handling is declarative and very flexible But you should test your assumptions! PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Error handlers Default Error handling: No redelivery Exceptions are propagated back to the caller / incoming endpointDefaultErrorHandler Default if none specified<retryable>DeadLetterChannel Implements DLQ pattern. Redirect message.<retryable> Also supports rolling back to original messageTransactionErrorHandler Only used for transactions<retryable>NoErrorHandler DummyLoggingErrorHandler Logging PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Error handler features errorHandler(defaultErrorHandler() .maximumRedeliveries(2) .redeliveryDelay(1000) .retryAttemptedLogLevel(LoggingLevel.WARN)); from("seda:queue.inbox") .beanRef("orderService", "validate") .beanRef("orderService", "enrich") .log("Received order ${body}") .to("mock:queue.order");Redelivery policies Specify retries, exponential backoff etc. Redelivery will be on the exception origin, NOT from the start of the routeScope Context or on a route basisException policies (onException(E)) Specific policies for particular exceptionsonWhen Even more fine-grained control. I.e check status code on Http exceptions. PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Exception policies onException(JmsException.class) .handled(true) .beanRef("errorFormatter"); from("jetty:http://0.0.0.0:80/orderservice") .beanRef("orderTransformer") .to("jms:queue:incomingOrders") .beanRef("orderAckTransformer");onException lets you provide granularity to exception handlinghandled(true) instructs the incoming endpoint to not throw exception back at callerBasically an alternative route for i.e constructing an error reply message, without it the consumer would get the actual exception PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Deployment optionsCamel is only a framework, not a deployment serverWAR, Java standalone, JMS Provider, ServiceMix OSGI, in- applicationThink about what Spring did for web app environment independence, Camel does the same for integration solutionsDoes not impose restrictions on deployment environment! PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • Proposed deployment pathCamel as stand-alone app or deployed into Jetty/TomcatGood for PoC and getting to know the frameworkAnother option is to bundle Jetty inside your application (as in demo) Tomcat/Jetty OrderRoutes.war camel- camel- camel- core file cxf P2pRoutes.war camel- camel- camel- core file cxf PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • For transactional use-cases and messaging, consider deploying to your standard Java EE container (JBoss, Glassfish, Weblogic, Websphere) Java EE container OrderRoutes.war camel- camel- camel- core jms jdbc P2pRoutes.war camel- camel- camel- core jms jdbc JMS / JPA / JTA JCA adapters DataSources PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • To scale – go full OSGI, deploying to Fuse ESB/ServiceMix Removes need to bundle Camel in application Makes multi-versions at runtime possible Extra features for route management etc.. Fuse ESB/ServiceMix camel-core 1.0 OrderRoutes.jar camel-jms 1.0 camel-jdbc 1.0 P2pRoutes.jar camel-... x.x PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • More info atCamel Official site http://camel.apache.org/FuseSource webinars http://fusesource.com/resources/video-archived-webinars/Open Source SOA with Fuse http://www.parleys.com/#sl=2&st=5&id=1577And of course, the Camel In Action book! PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
    • DEMO!PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING