Message Broker Integration
Total Page:16
File Type:pdf, Size:1020Kb
1 Event Driven Architectures with Camel Gnanaguru Sattanathan Prajod Vettiyattil Twitter:@gnanagurus Twitter: @prajods Website: bushorn.com 2 What this session is about v Application Integration v Apache Camel v Event Driven Architectures with Camel 3 Application Integration 4 Integration JMS, 1. Validate, Enrich, Route, RMI, Transform JDBC, 2. Diverse protocol support FTP, SNMP, TCP Middleware https, SFTP, SNMP, 1. Enterprise Service Bus TCP, 2. Integration Framework CORBA 5 The Chameleon 6 Camel is a reptile ! 7 The Chameleon It can change color with the container J Camel Camel Camel Camel Camel Camel Oracle JVM Tomcat JBoss Websphere Jetty Fusion 8 Apache Camel • Integration framework • Multiple deployment options • Feature rich • Simple to program • Unique scalability features • Apache License 9 Apache Camel: Components • More than 100 readymade components • Covering – PaaS & Public Clouds – Social Networks – Devices – Almost all standard protocols 10 Apache Camel: Components AWS HDFS MongoDB ActiveMQ Twitter FILE JDBC JMS SFTP Streams JGroups AMQP MQTT NETTY SQL SIP UDP Cache Esper Hazelcast Zoo Keeper WebSockets SMTP SSH SMPP SOLR RMI Velocity Smooks XQuery XSLT NMR TCP 11 Coding with Camel 12 Camel – Code your way JAVA Domain Specific Language SPRING (DSL) GROOVY SCALA 13 A simple file integration File File System Input Output Directory Directory 14 Simple file integration: Sample Code <route> <from uri="file://d:\Input"/> <to uri="file://d:\Output"/> </route> using Spring XML 15 File System – Message Broker Integration File File System Message Broker ( ActiveMQ) Input Output Directory Queue 16 File System to Message Broker Integration: Sample Code <route> <from uri="file://d:\Input"/> <to uri="activemq:queue:Output"/> </route> using Spring XML 17 Adding a simple transformation File File System Message Broker ( ActiveMQ) Input Output Directory Queue Transformer Transformer 18 A simple transformation: Sample Code <route> <from uri="file://d:\Input"/> <to uri="xslt:file://d:\transform.xsl"/> <to uri="activemq:queue:Output"/> </route> using Spring XML 19 A simple Twitter application Twitter.com Message Broker ( ActiveMQ) Tweets TweetsTweets Queue 20 A simple Twitter application: Sample Code <route> <from uri="twitter://search ?type=direct &keywords=JUDCON”/ > <to uri="activemq:queue:Output"/> </route>21 Event Driven Architectures with Camel 22 Event Driven Architecture • EDA • A software architecture pattern • Event: Significant change in state • Parts of the architecture – Event source – Event channel – Event processor 23 EDA Source Source Source Source Source Source Sources 1 2 3 4 5 6 Channels Channels Event Event Event Processor 1 Processor 2 Processor 3 Processors 24 Staged Event Driven Architecture(SEDA) • EDA – Direct and tight coupling of sources and processors – Event processor may get swamped with events • Reduces performance • Possible loss of messages • SEDA – EDA decomposed into stages and connected with queues 25 SEDA: one view Source Source Source Source Source Source 1 2 3 4 5 6 Stage 1 Channels Channels using Queues Channels using Queues Event Event Event Processor 1 Processor 2 Processor 3 Stage 2 26 SEDA: another view Processor Queue Source 2 1 Queue Processor 1 Source 2 Processor Queue 3 Stage 1 Channels using Stage 2 Channels using Stage 3 Queues Queues 27 SEDA with Camel • SEDA – Scalability feature in Camel – Uses thread pools and internal queues – Enables parallel processing – Avoids waiting threads 28 Camel with SEDA: comparison Waiting thread without SEDA Parallel processing with SEDA Receive Receive SEDA Queue 1 Validate Thread 1 Thread 2 Validate Normalize Thread 1 Normalize Enrich SEDA Queue 2 Split Split Enrich Route Route Thread 3 • Impact • For 100 concurrent requests – significant reduction in thread – Without SEDA: 100 threads; With SEDA: 30 threads 29 consumption Camel as a part of EDA • Camel as – Event channel – Event processor Camel 30 Camel as Event Channel • SEDA queues • VM queues • Multi-threaded flow • Load balanced flow • Asynchronous API 31 Camel as Event Processor • Not ideal as the final Event Processor • Can be used as an intermediate Event processor • Routing based on events • Transformation of events • Combining simple events • Event auditing, logging 32 Camel and the Actor Model with Akka • Actor Model Actor – Actors Behavior • Similar to objects, many other features • Mailbox, behavior/s, internal state Mailbox State – No shared state – Messages between actors – Locking and Threads are abstracted – Each actor instance runs in its own thread • Akka-Camel – Integrate Akka to other applications – Two way: Akka to Camel and Camel to Akka 33 Summary • Camel – Integration Framework – Simplicity and flexibility – Components • EDA with Camel – SEDA – SEDA within Camel – Camel as part of SEDA • Akka and Camel for EDA 34 Questions Gnanaguru Sattanathan Prajod Vettiyattil Twitter:@gnanagurus Twitter: @prajods Website: bushorn.com Our Open Source Middleware Group on LinkedIn http://tinyurl.com/be6e93q 35 .