SlideShare a Scribd company logo
Enterprise Application Integration and
                                 Batch Processing in the Cloud
                                          Josh Long, Spring Developer Advocate
                                       josh.long@springsource.com @starbuxman




© 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Josh Long
Spring Developer Advocate
josh.long@springsource.com @starbuxman




  2
Worker processes on Cloud Foundry
Lots of Potential
 http://blog.springsource.org/2012/05/09/using-cloud-foundry-workers-with-spring/
 lots of use cases                             ---
                                                applications:
  • background jobs                               target/appassembler/:
  • headless applications                           name: integration-service
  • batch jobs                                      framework:
  • embedded web servers                              name: standalone
                                                   info:
                                                     mem: 64M
                                                     description: Standalone Application
                                                     exec:
                                                 runtime: java
                                                 command: bin/main
                                                 url:
                                                 mem: 512M
                                                 instances: 1
                                                 services:
                                                   stock_rabbitmq:
                                                     type: rabbitmq

   4
Easy to Package Multi-component Java applications
     <build>
            <plugins>
                 <plugin>
                     <groupId>org.codehaus.mojo</groupId>
                     <artifactId>appassembler-maven-plugin</artifactId>
                     <executions>
                          <execution>
                              <phase>package</phase>
                              <goals>
                                  <goal>assemble</goal>
                              </goals>
                              <configuration>
                                  <assembledirectory>target</assembledirectory>
                                  <programs>
                                       <program>
                                           <mainClass>org.cloudfoundry.workers.stocks.integration.service.Main</mainClass>
                                       </program>
                                  </programs>
                              </configuration>
                          </execution>
                     </executions>
                 </plugin>
            </plugins>
        </build>




 5
Cloud Scale Messaging with RabbitMQ
First, an Introduction to
   AMQP & RabbitMQ
Messaging Use Cases




                             Decoupling

                  producer                                       consumer



               shopping cart sending request CC merchant




                                        NOT CONFIDENTIAL -- TELL EVERYONE   8
Messaging Use Cases




                              Bidirectional Decoupling


                  producer                                            consumer



                 eg: remote procedure call




                                         NOT CONFIDENTIAL -- TELL EVERYONE       9
Messaging Use Cases




                        Bidirectional Decoupling


           producer                                       producer



           consumer


         eg: place order and wait for confirmation




                                             NOT CONFIDENTIAL -- TELL EVERYONE   10
Messaging Use Cases




                        Bidirectional Decoupling


           producer                                     consumer producer



           consumer


         eg: place order and wait for confirmation




                                             NOT CONFIDENTIAL -- TELL EVERYONE   11
Messaging Use Cases




                   work distribution and decoupling

                                                                      consumer

           producer                                                   consumer




         distribution can be duplicate or round-robin:
         - duplication for information (logging, auditing, etc)
         - round robin for scaling and load balancing




                                              NOT CONFIDENTIAL -- TELL EVERYONE   12
Messaging Use Cases

 Other Things a Message Broker Can Do
 • Store-and-forward of messages
 • Absorbing spikes of activity (again, decoupling)
 • Routing to different consumers based on message properties




                                                      NOT CONFIDENTIAL -- TELL EVERYONE   13
AMQP and JMS




               How does AMQP compare to JMS?
               When would I use one or the other?




                             NOT CONFIDENTIAL -- TELL EVERYONE   14
AMQP and JMS


  AMQP                                                   JMS
  Protocol                                               API
  No language                                            Java
  Industry committee, mainly finance                     JEE

  Interoperability from client libraries                 Interoperability from proprietary features

  Resources can be managed by clients                    Resources often centrally managed

  Not ubiquitous in enterprise                           Ubiquitous through JEE

  Flexible usage patterns, emphasise routing             Two basic producer patterns (Queue and Topic)


  Designed for large numbers of queues and exchanges     Hard to manage large numbers of Destinations




                                                  NOT CONFIDENTIAL -- TELL EVERYONE                      15
AMQP and JMS

 JMS
 • standard in the Java space
 • lots of open source options
 • provided with Java EE application servers
 • Spring JMS



                         Java producers          Message broker   Java consumers


                                                                      C
                             P                 queue

                                                                      C

                             P                 queue
                                                                      C


                                                                                   16
JMS

     Sending JMS Messages
     • Inject an instance of Spring's JmsTemplate.
     • Provide the JMS ConnectionFactory in the JmsTemplate bean definition.

@Component
public class MessageSender {

    @Autowired
    private volatile JmsTemplate jmsTemplate;

    public void send(String message) {
      this.jmsTemplate.convertAndSend("example.queue", message);
    }

}                                        @Bean public ConnnectionFactory cf (){
                                            return new CachingConnectionFactory(...);
                                         }
                                         @Bean public JmsTemplate template(){
                                           return new JmsTemplate(this.cf()) ;
                                         }


                                                                                        17
AMQP and JMS

 AMQP
 • real standard
 • a product of the the companies with the most mission critical requirements
 • Spring AMQP


 AMQP producers                exchanges                  Message broker        AMQP consumers


                                                                                       C
                     P              X                queue

                                                                                       C

                     P               X               queue
                                                                                       C




                                                                                                 1
AMQP and JMS

 JMS Topic Explosion:
 • Messages with fine-grained routing, e.g.
   • Market data: region, country, exchange, ticker, …
   • Online gambling: sport, match, event-type, …
   • Message selectors are inefficient and fiddly to work with in the API
 • Exponential explosion of possible combinations of interesting subscriptions
 • Can implement as hierarchy of Topics
 • 1000s or 10000s of Destinations
 • Management nightmare
 • Sweet spot for AMQP




                                                         NOT CONFIDENTIAL -- TELL EVERYONE   19
AMQP

     Sending AMQP Messages
     • Use AmqpTemplate instead of JmsTemplate (accepts exchange and routingKey).
     • Nothing changes on the listener side (just a POJO).



@Component public class MessageSender {

    @Autowired
    private volatile AmqpTemplate amqpTemplate;

    public void send(String message) {
      this.amqpTemplate.convertAndSend(
              "myExchange", "some.routing.key", message);
    }

}




                                                                                    20
Spring AMQP
    Java and .NET
    AMQP core abstraction plus RabbitMQ implementation (built on rabbit client libraries)
    Higher level patterns for clients: admin, producers and consumers
        RabbitAdmin – declare exchanges, queues, bindings
        RabbitTemplate – convenience methods for send and receive
        MessageListenerContainer – POJO message handler, asynchronous
    Spring Integration support
 http://www.springsource.org/spring-amqp




                                                     NOT CONFIDENTIAL -- TELL EVERYONE       21
Spring AMQP: RabbitTemplate


public class MyComponent {
  private RabbitTemplate rabbitTemplate;

    public MyComponent(ConnectionFactory connectionFactory) {
      this.rabbitTemplate = new RabbitTemplate(connectionFactory);
    }

    public void read() throws Exception {
       ...
      String value = rabbitTemplate.receiveAndConvert("myQueueName");
      ...
    }

}
                                                                        Convenience methods




                                                         NOT CONFIDENTIAL -- TELL EVERYONE    22
Spring AMQP: SimpleMessageListenerContainer
    Asynchronous message receiver
    POJO handlers
    Handles re-connection and listener failure (rollback, redelivery)
    Message conversion and error handling strategies



             <listener-container connection-factory="connectionFactory">
              <listener ref="handler" method="handle" queue-names="my.queue">
             </listener-container>




                                                  NOT CONFIDENTIAL -- TELL EVERYONE   23
Messaging Use Cases

 Patterns:
 spatial decoupling (aka communication)
 temporal decoupling (aka buffering)
 logical decoupling (aka routing)
 Promote: flexibility, resilience, performance, and scale
 Conclusion: There is an enormous range of applications and problems to which messaging is
 an effective solution.




                                           NOT CONFIDENTIAL -- TELL EVERYONE                  24
Not confidential. Tell everyone.   25
Not confidential. Tell everyone.   26
Batch Processing in the Cloud




     Not confidential. Tell everyone.   27
First, an Introduction to Spring Batch




         Not confidential. Tell everyone.   28
Why we’re here...




                    Not confidential. Tell everyone.   29
...So, What’s the Problem?




    Not confidential. Tell everyone.   30
Job and Step




                   Job
                                        *                       Step
               *
                   JobInstance

                                                                       Step Scope
                          *
                         JobExecution
                                                                       * StepExecution



                                 Not confidential. Tell everyone.                        31
Getting Started




               Application
               Developer
                             implements                                                                ItemProcessor (optional)

                                                                                              input                               output (optional)
       configures
                                                                                   ItemReader                   ItemWriter




                                              Job

                                          *                                        StepExecutor concerns
                                              Step


                                                                            RepeatOperations               ExceptionHandler




                                                Not confidential. Tell everyone.                                                                      32
Spring Batch

 Supports Batch API...
 • Jobs have Steps
 • Steps have Readers, and optional Processors and Writers
  • Readers read data
  • Processors process data coming into them, optionally transforming it. Optional.
  • Writers write data out




                                             Not confidential. Tell everyone.         33
ItemReader




            public interface ItemReader<T> {

            	     T read() throws Exception,
                           UnexpectedInputException,
                           ParseException,
                           NonTransientResourceException;

            }
Returns null at end of dataset

                                                                       delegate Exception handling to framework




                                    Not confidential. Tell everyone.                                              34
ItemProcessor (Optional)




                   public interface ItemProcessor<I, O> {
                     O process(I item) throws Exception;
                   }




Delegate Exception handling to framework




                                           Not confidential. Tell everyone.   35
ItemWriter




           public interface ItemWriter<T> {

           	        void write(List<? extends T> items) throws Exception;

           }




expects a “chunk”

                                                                          delegate Exception handling to framework




                                       Not confidential. Tell everyone.                                              36
All Together...


        <job id="skipJob" incrementer="incrementer"
           xmlns="http://www.springframework.org/schema/batch">

            <step id="step1">
             <tasklet>

              <chunk reader="fileItemReader"
                      processor="tradeProcessor"
                      writer="tradeWriter"
                      commit-interval="3" skip-limit="10">
        	       </chunk>
        	      </tasklet>
        	      <next on="*" to="step2" />

        	     <next on="COMPLETED WITH SKIPS" to="errorPrint1" />

        	     <fail on="FAILED" exit-code="FAILED" />

            </step>

         ...
        </job>




                                               Not confidential. Tell everyone.   37
Partitioning Overview




                        Job


                        Step



                        Step



                        Step




                               Not confidential. Tell everyone.   38
Partitioning Overview




                         Job

                                                                    Slave
                        Step
                                                                    Slave

                                                                    Slave
                        Master
                                                                    Slave

                                                                    Slave
                        Step
                                                                    Slave




                                 Not confidential. Tell everyone.           39
Requests


We Have a Cloud, Let’s Scale!

 Spring Batch supports Remote Chunking over AMQP
 • http://labs.bsb.com/2011/11/remote-partitioning-with-spring-batch/
 • http://bit.ly/wrb8Ch
                               master



                                                              step execution results




                                                              RabbitMQ


                      Step Execution
                         Requests




                                                          slave 1                      slave 2   slave 3




                                              Not confidential. Tell everyone.                             40
Simple Strategy SPI for Distribution and Aggregation




                               Not confidential. Tell everyone.   41
Application Integration (in the Cloud)




         Not confidential. Tell everyone.   42
Integration's More Common Than You Think




                                     channel
                                    System A




        System A
        System A                                                System B


                             Not confidential. Tell everyone.              43
                                                                             6
Nobody Builds Systems in a Vacuum




                                                               do NOT reinvent
                                                               the Wheel!




                            Not confidential. Tell everyone.                     44
Don't over extend your architecture!
                    Not confidential. Tell everyone.   45
Rooted in Classic Patterns


 •   By Gregor Hohpe & Bobby Woolf
 •   Published 2003
 •   Collection of well-known patterns
 •   http://www.eaipatterns.com/eaipatterns.html
 •   Icon library provided




                                 Not confidential. Tell everyone.   46
What is Spring Integration?

• Light-weight messaging framework
• Provides an adapter-based platform

• Pipes and Filters at the core of Spring Integration’s architecture
  – Endpoint (Filter)
  – Channel (Pipe)
  – Message




                                 Not confidential. Tell everyone.      47
DEMO
• Spring Integration Primer




                              @starbuxman   slideshare.net/joshlong
Spring Integration @Gateway

 Gateways...
 • hide one system from the messaging semantics of another
 • Support all the message exchange patterns
  • Request
  • Request asynchronous (fire-n-forget)
  • Request/Reply
  • Request/Reply asynchronous (fire-n-forget)


  public class CustomerService {
   void addCustomer( Customer customer )
     throws CrmException;

  }




                                             Not confidential. Tell everyone.   49
Spring Integration @Gateway



  MessageChannel crmChannel = ...;

  MessagingOperations operations = .... ;

  operations.sendAndReceive( crmChannel ,
   MessageBuilder.withPayload(new Customer(..)).build() );




                              Not confidential. Tell everyone.   50
Spring Integration @Gateway




     public interface CustomerService {
      @Gateway
      void addCustomer( Customer customer )
        throws CrmException;

     }




                              Not confidential. Tell everyone.   51
DEMO
• using Spring Integration gateways




                                      @starbuxman   slideshare.net/joshlong
Summary

 RabbitMQ is readily available Messaging in the Cloud
 Spring Integration makes integration over AMQP easy
 Spring Batch Makes Batch Jobs Easy
 • Remote Chunking Makes Using AMQP as the Coordination Fabric Easy




                                      Not confidential. Tell everyone.   53
springsource.org | cloudfoundry.org




            Questions?
                Say hi!
       @starbuxman      slideshare.net/joshlong
@starbuxman josh.long@springsource.com

More Related Content

PDF
Developing real-time data pipelines with Spring and Kafka
PPTX
Introduction to Kafka with Spring Integration
PPT
How To Scale v2
PDF
Apache ActiveMQ
PPTX
Kafka Connect
PPT
Semantic Search Engines
PDF
What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...
PPTX
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Developing real-time data pipelines with Spring and Kafka
Introduction to Kafka with Spring Integration
How To Scale v2
Apache ActiveMQ
Kafka Connect
Semantic Search Engines
What is the State of my Kafka Streams Application? Unleashing Metrics. | Neil...
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021

What's hot (20)

PPTX
Connection Pooling
PDF
Uber: Kafka Consumer Proxy
PPTX
Service messaging using Kafka
PDF
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
PDF
Connecting Apache Kafka With Mule ESB
ODP
Red Hat Open Day JBoss Fuse
PDF
What’s new in Nuxeo 5.2?
PDF
Coherence Implementation Patterns - Sig Nov 2011
PDF
Kafka on Pulsar:bringing native Kafka protocol support to Pulsar_Sijie&Pierre
PPTX
Coherence sig-nfr-web-tier-scaling-using-coherence-web
PPTX
Event sourcing Live 2021: Streaming App Changes to Event Store
PPTX
Running MariaDB in multiple data centers
PDF
HTML5 Server Sent Events/JSF JAX 2011 Conference
PDF
Function Mesh for Apache Pulsar, the Way for Simple Streaming Solutions
PPTX
MySQL Multi Master Replication
PDF
Design and Implementation of Incremental Cooperative Rebalancing
PDF
Performance Tuning Oracle Weblogic Server 12c
PDF
Consumer offset management in Kafka
PDF
Operationalizing Machine Learning: Serving ML Models
PDF
Stream-Native Processing with Pulsar Functions
Connection Pooling
Uber: Kafka Consumer Proxy
Service messaging using Kafka
Galera Cluster for MySQL vs MySQL (NDB) Cluster: A High Level Comparison
Connecting Apache Kafka With Mule ESB
Red Hat Open Day JBoss Fuse
What’s new in Nuxeo 5.2?
Coherence Implementation Patterns - Sig Nov 2011
Kafka on Pulsar:bringing native Kafka protocol support to Pulsar_Sijie&Pierre
Coherence sig-nfr-web-tier-scaling-using-coherence-web
Event sourcing Live 2021: Streaming App Changes to Event Store
Running MariaDB in multiple data centers
HTML5 Server Sent Events/JSF JAX 2011 Conference
Function Mesh for Apache Pulsar, the Way for Simple Streaming Solutions
MySQL Multi Master Replication
Design and Implementation of Incremental Cooperative Rebalancing
Performance Tuning Oracle Weblogic Server 12c
Consumer offset management in Kafka
Operationalizing Machine Learning: Serving ML Models
Stream-Native Processing with Pulsar Functions
Ad

Similar to Integration and Batch Processing on Cloud Foundry (20)

PDF
JVM Multitenancy (JavaOne 2012)
PDF
Tungsten University: Configure and provision Tungsten clusters
PPTX
vFabric - Ideal Platform for SaaS Apps
PDF
Hive solutions cloudviews 2010 presentation
PDF
colony framework & omni platform
KEY
Spring in the Cloud - using Spring with Cloud Foundry
PPTX
15 ways-to-optimize-spring-boot-for-the-cloud
PDF
Virtualization aware Java VM
PDF
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
PPTX
15-ways-to-optimize-spring-boot-for-the-cloud
PDF
Cloud Best Practices
PPTX
Architecting a Private Cloud - Cloud Expo
PPTX
Docker Swarm secrets for creating great FIWARE platforms
KEY
Multi client Development with Spring
PDF
Cloud Native Camel Design Patterns
PDF
Spring Boot & Spring Cloud on PAS- Nate Schutta (2/2)
PDF
Introducing CQ 5.1
PDF
Plugin-able POS Solutions by Javascript @HDM9 Taiwan
PPT
IBM Pulse 2013 session - DevOps for Mobile Apps
PDF
Enterprise Cloud with IBM & Chef (ChefConf 2013)
JVM Multitenancy (JavaOne 2012)
Tungsten University: Configure and provision Tungsten clusters
vFabric - Ideal Platform for SaaS Apps
Hive solutions cloudviews 2010 presentation
colony framework & omni platform
Spring in the Cloud - using Spring with Cloud Foundry
15 ways-to-optimize-spring-boot-for-the-cloud
Virtualization aware Java VM
FIWARE Tech Summit - Docker Swarm Secrets for Creating Great FIWARE Platforms
15-ways-to-optimize-spring-boot-for-the-cloud
Cloud Best Practices
Architecting a Private Cloud - Cloud Expo
Docker Swarm secrets for creating great FIWARE platforms
Multi client Development with Spring
Cloud Native Camel Design Patterns
Spring Boot & Spring Cloud on PAS- Nate Schutta (2/2)
Introducing CQ 5.1
Plugin-able POS Solutions by Javascript @HDM9 Taiwan
IBM Pulse 2013 session - DevOps for Mobile Apps
Enterprise Cloud with IBM & Chef (ChefConf 2013)
Ad

More from Joshua Long (20)

PDF
Economies of Scaling Software
PDF
Bootiful Code with Spring Boot
PDF
Microservices with Spring Boot
PDF
Boot It Up
PDF
Have You Seen Spring Lately?
PDF
Java Configuration Deep Dive with Spring
PDF
the Spring Update from JavaOne 2013
PDF
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
PDF
REST APIs with Spring
PDF
the Spring 4 update
PDF
Extending spring
PDF
The spring 32 update final
KEY
Multi Client Development with Spring
KEY
using Spring and MongoDB on Cloud Foundry
PDF
Spring in-the-cloud
KEY
Multi Client Development with Spring
KEY
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
KEY
A Walking Tour of (almost) all of Springdom
KEY
Spring Batch Behind the Scenes
KEY
Cloud Foundry Bootcamp
Economies of Scaling Software
Bootiful Code with Spring Boot
Microservices with Spring Boot
Boot It Up
Have You Seen Spring Lately?
Java Configuration Deep Dive with Spring
the Spring Update from JavaOne 2013
Multi Client Development with Spring for SpringOne 2GX 2013 with Roy Clarkson
REST APIs with Spring
the Spring 4 update
Extending spring
The spring 32 update final
Multi Client Development with Spring
using Spring and MongoDB on Cloud Foundry
Spring in-the-cloud
Multi Client Development with Spring
The Cloud Foundry bootcamp talk from SpringOne On The Road - Europe
A Walking Tour of (almost) all of Springdom
Spring Batch Behind the Scenes
Cloud Foundry Bootcamp

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Big Data Technologies - Introduction.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
A Presentation on Artificial Intelligence
Big Data Technologies - Introduction.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks

Integration and Batch Processing on Cloud Foundry

  • 1. Enterprise Application Integration and Batch Processing in the Cloud Josh Long, Spring Developer Advocate josh.long@springsource.com @starbuxman © 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission.
  • 2. Josh Long Spring Developer Advocate josh.long@springsource.com @starbuxman 2
  • 3. Worker processes on Cloud Foundry
  • 4. Lots of Potential  http://blog.springsource.org/2012/05/09/using-cloud-foundry-workers-with-spring/  lots of use cases --- applications: • background jobs target/appassembler/: • headless applications name: integration-service • batch jobs framework: • embedded web servers name: standalone info: mem: 64M description: Standalone Application exec: runtime: java command: bin/main url: mem: 512M instances: 1 services: stock_rabbitmq: type: rabbitmq 4
  • 5. Easy to Package Multi-component Java applications <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>appassembler-maven-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>assemble</goal> </goals> <configuration> <assembledirectory>target</assembledirectory> <programs> <program> <mainClass>org.cloudfoundry.workers.stocks.integration.service.Main</mainClass> </program> </programs> </configuration> </execution> </executions> </plugin> </plugins> </build> 5
  • 6. Cloud Scale Messaging with RabbitMQ
  • 7. First, an Introduction to AMQP & RabbitMQ
  • 8. Messaging Use Cases Decoupling producer consumer shopping cart sending request CC merchant NOT CONFIDENTIAL -- TELL EVERYONE 8
  • 9. Messaging Use Cases Bidirectional Decoupling producer consumer eg: remote procedure call NOT CONFIDENTIAL -- TELL EVERYONE 9
  • 10. Messaging Use Cases Bidirectional Decoupling producer producer consumer eg: place order and wait for confirmation NOT CONFIDENTIAL -- TELL EVERYONE 10
  • 11. Messaging Use Cases Bidirectional Decoupling producer consumer producer consumer eg: place order and wait for confirmation NOT CONFIDENTIAL -- TELL EVERYONE 11
  • 12. Messaging Use Cases work distribution and decoupling consumer producer consumer distribution can be duplicate or round-robin: - duplication for information (logging, auditing, etc) - round robin for scaling and load balancing NOT CONFIDENTIAL -- TELL EVERYONE 12
  • 13. Messaging Use Cases  Other Things a Message Broker Can Do • Store-and-forward of messages • Absorbing spikes of activity (again, decoupling) • Routing to different consumers based on message properties NOT CONFIDENTIAL -- TELL EVERYONE 13
  • 14. AMQP and JMS How does AMQP compare to JMS? When would I use one or the other? NOT CONFIDENTIAL -- TELL EVERYONE 14
  • 15. AMQP and JMS AMQP JMS Protocol API No language Java Industry committee, mainly finance JEE Interoperability from client libraries Interoperability from proprietary features Resources can be managed by clients Resources often centrally managed Not ubiquitous in enterprise Ubiquitous through JEE Flexible usage patterns, emphasise routing Two basic producer patterns (Queue and Topic) Designed for large numbers of queues and exchanges Hard to manage large numbers of Destinations NOT CONFIDENTIAL -- TELL EVERYONE 15
  • 16. AMQP and JMS  JMS • standard in the Java space • lots of open source options • provided with Java EE application servers • Spring JMS Java producers Message broker Java consumers C P queue C P queue C 16
  • 17. JMS  Sending JMS Messages • Inject an instance of Spring's JmsTemplate. • Provide the JMS ConnectionFactory in the JmsTemplate bean definition. @Component public class MessageSender { @Autowired private volatile JmsTemplate jmsTemplate; public void send(String message) { this.jmsTemplate.convertAndSend("example.queue", message); } } @Bean public ConnnectionFactory cf (){ return new CachingConnectionFactory(...); } @Bean public JmsTemplate template(){ return new JmsTemplate(this.cf()) ; } 17
  • 18. AMQP and JMS  AMQP • real standard • a product of the the companies with the most mission critical requirements • Spring AMQP AMQP producers exchanges Message broker AMQP consumers C P X queue C P X queue C 1
  • 19. AMQP and JMS  JMS Topic Explosion: • Messages with fine-grained routing, e.g. • Market data: region, country, exchange, ticker, … • Online gambling: sport, match, event-type, … • Message selectors are inefficient and fiddly to work with in the API • Exponential explosion of possible combinations of interesting subscriptions • Can implement as hierarchy of Topics • 1000s or 10000s of Destinations • Management nightmare • Sweet spot for AMQP NOT CONFIDENTIAL -- TELL EVERYONE 19
  • 20. AMQP  Sending AMQP Messages • Use AmqpTemplate instead of JmsTemplate (accepts exchange and routingKey). • Nothing changes on the listener side (just a POJO). @Component public class MessageSender { @Autowired private volatile AmqpTemplate amqpTemplate; public void send(String message) { this.amqpTemplate.convertAndSend( "myExchange", "some.routing.key", message); } } 20
  • 21. Spring AMQP  Java and .NET  AMQP core abstraction plus RabbitMQ implementation (built on rabbit client libraries)  Higher level patterns for clients: admin, producers and consumers  RabbitAdmin – declare exchanges, queues, bindings  RabbitTemplate – convenience methods for send and receive  MessageListenerContainer – POJO message handler, asynchronous  Spring Integration support http://www.springsource.org/spring-amqp NOT CONFIDENTIAL -- TELL EVERYONE 21
  • 22. Spring AMQP: RabbitTemplate public class MyComponent { private RabbitTemplate rabbitTemplate; public MyComponent(ConnectionFactory connectionFactory) { this.rabbitTemplate = new RabbitTemplate(connectionFactory); } public void read() throws Exception { ... String value = rabbitTemplate.receiveAndConvert("myQueueName"); ... } } Convenience methods NOT CONFIDENTIAL -- TELL EVERYONE 22
  • 23. Spring AMQP: SimpleMessageListenerContainer  Asynchronous message receiver  POJO handlers  Handles re-connection and listener failure (rollback, redelivery)  Message conversion and error handling strategies <listener-container connection-factory="connectionFactory"> <listener ref="handler" method="handle" queue-names="my.queue"> </listener-container> NOT CONFIDENTIAL -- TELL EVERYONE 23
  • 24. Messaging Use Cases  Patterns:  spatial decoupling (aka communication)  temporal decoupling (aka buffering)  logical decoupling (aka routing)  Promote: flexibility, resilience, performance, and scale  Conclusion: There is an enormous range of applications and problems to which messaging is an effective solution. NOT CONFIDENTIAL -- TELL EVERYONE 24
  • 25. Not confidential. Tell everyone. 25
  • 26. Not confidential. Tell everyone. 26
  • 27. Batch Processing in the Cloud Not confidential. Tell everyone. 27
  • 28. First, an Introduction to Spring Batch Not confidential. Tell everyone. 28
  • 29. Why we’re here... Not confidential. Tell everyone. 29
  • 30. ...So, What’s the Problem? Not confidential. Tell everyone. 30
  • 31. Job and Step Job * Step * JobInstance Step Scope * JobExecution * StepExecution Not confidential. Tell everyone. 31
  • 32. Getting Started Application Developer implements ItemProcessor (optional) input output (optional) configures ItemReader ItemWriter Job * StepExecutor concerns Step RepeatOperations ExceptionHandler Not confidential. Tell everyone. 32
  • 33. Spring Batch  Supports Batch API... • Jobs have Steps • Steps have Readers, and optional Processors and Writers • Readers read data • Processors process data coming into them, optionally transforming it. Optional. • Writers write data out Not confidential. Tell everyone. 33
  • 34. ItemReader public interface ItemReader<T> { T read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException; } Returns null at end of dataset delegate Exception handling to framework Not confidential. Tell everyone. 34
  • 35. ItemProcessor (Optional) public interface ItemProcessor<I, O> { O process(I item) throws Exception; } Delegate Exception handling to framework Not confidential. Tell everyone. 35
  • 36. ItemWriter public interface ItemWriter<T> { void write(List<? extends T> items) throws Exception; } expects a “chunk” delegate Exception handling to framework Not confidential. Tell everyone. 36
  • 37. All Together... <job id="skipJob" incrementer="incrementer" xmlns="http://www.springframework.org/schema/batch"> <step id="step1"> <tasklet> <chunk reader="fileItemReader" processor="tradeProcessor" writer="tradeWriter" commit-interval="3" skip-limit="10"> </chunk> </tasklet> <next on="*" to="step2" /> <next on="COMPLETED WITH SKIPS" to="errorPrint1" /> <fail on="FAILED" exit-code="FAILED" /> </step> ... </job> Not confidential. Tell everyone. 37
  • 38. Partitioning Overview Job Step Step Step Not confidential. Tell everyone. 38
  • 39. Partitioning Overview Job Slave Step Slave Slave Master Slave Slave Step Slave Not confidential. Tell everyone. 39
  • 40. Requests We Have a Cloud, Let’s Scale!  Spring Batch supports Remote Chunking over AMQP • http://labs.bsb.com/2011/11/remote-partitioning-with-spring-batch/ • http://bit.ly/wrb8Ch master step execution results RabbitMQ Step Execution Requests slave 1 slave 2 slave 3 Not confidential. Tell everyone. 40
  • 41. Simple Strategy SPI for Distribution and Aggregation Not confidential. Tell everyone. 41
  • 42. Application Integration (in the Cloud) Not confidential. Tell everyone. 42
  • 43. Integration's More Common Than You Think channel System A System A System A System B Not confidential. Tell everyone. 43 6
  • 44. Nobody Builds Systems in a Vacuum do NOT reinvent the Wheel! Not confidential. Tell everyone. 44
  • 45. Don't over extend your architecture! Not confidential. Tell everyone. 45
  • 46. Rooted in Classic Patterns • By Gregor Hohpe & Bobby Woolf • Published 2003 • Collection of well-known patterns • http://www.eaipatterns.com/eaipatterns.html • Icon library provided Not confidential. Tell everyone. 46
  • 47. What is Spring Integration? • Light-weight messaging framework • Provides an adapter-based platform • Pipes and Filters at the core of Spring Integration’s architecture – Endpoint (Filter) – Channel (Pipe) – Message Not confidential. Tell everyone. 47
  • 48. DEMO • Spring Integration Primer @starbuxman slideshare.net/joshlong
  • 49. Spring Integration @Gateway  Gateways... • hide one system from the messaging semantics of another • Support all the message exchange patterns • Request • Request asynchronous (fire-n-forget) • Request/Reply • Request/Reply asynchronous (fire-n-forget) public class CustomerService { void addCustomer( Customer customer ) throws CrmException; } Not confidential. Tell everyone. 49
  • 50. Spring Integration @Gateway MessageChannel crmChannel = ...; MessagingOperations operations = .... ; operations.sendAndReceive( crmChannel , MessageBuilder.withPayload(new Customer(..)).build() ); Not confidential. Tell everyone. 50
  • 51. Spring Integration @Gateway public interface CustomerService { @Gateway void addCustomer( Customer customer ) throws CrmException; } Not confidential. Tell everyone. 51
  • 52. DEMO • using Spring Integration gateways @starbuxman slideshare.net/joshlong
  • 53. Summary  RabbitMQ is readily available Messaging in the Cloud  Spring Integration makes integration over AMQP easy  Spring Batch Makes Batch Jobs Easy • Remote Chunking Makes Using AMQP as the Coordination Fabric Easy Not confidential. Tell everyone. 53
  • 54. springsource.org | cloudfoundry.org Questions? Say hi! @starbuxman slideshare.net/joshlong @starbuxman josh.long@springsource.com

Editor's Notes

  • #2: \n
  • #3: \n
  • #4: \n
  • #5: \n
  • #6: \n
  • #7: \n
  • #8: \n
  • #9: \n
  • #10: \n
  • #11: \n
  • #12: \n
  • #13: \n
  • #14: \n
  • #15: \n
  • #16: \n
  • #17: the toolchain is STS, java compiler (no startup scripts required!) \nintroduce Spring Roo\nintroduce the Appcontexts\nintroduce the various Di configuration types \n\n
  • #18: \n
  • #19: the toolchain is STS, java compiler (no startup scripts required!) \nintroduce Spring Roo\nintroduce the Appcontexts\nintroduce the various Di configuration types \n\n
  • #20: \n
  • #21: \n
  • #22: \n
  • #23: \n
  • #24: \n
  • #25: \n
  • #26: \n
  • #27: \n
  • #28: A better approach is decompose the war into a set of services.\nYou can do that either by nouns or by verbs.\n\n
  • #29: A better approach is decompose the war into a set of services.\nYou can do that either by nouns or by verbs.\n\n
  • #30: Example of what can happen if you run processes more than correct number of times.\n
  • #31: A better approach is decompose the war into a set of services.\nYou can do that either by nouns or by verbs.\n\n
  • #32: \n
  • #33: \n
  • #34: \n
  • #35: \n
  • #36: \n
  • #37: \n
  • #38: \n
  • #39: \n
  • #40: \n
  • #41: \n
  • #42: \n
  • #43: A better approach is decompose the war into a set of services.\nYou can do that either by nouns or by verbs.\n\n
  • #44: A better approach is decompose the war into a set of services.\nYou can do that either by nouns or by verbs.\n\n
  • #45: \n
  • #46: \n
  • #47: \n
  • #48: \n
  • #49: \n
  • #50: talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  • #51: \n
  • #52: \n
  • #53: \n
  • #54: talk about how convenient the messaging support is, then roll back and start looking at how u might do the same thing manually. Explain that many of the pices are already there, and then seguqe into a discussion about the core Spring APIs. Lets imagine we&amp;#x2019;re going to build ourselves a file system poller to notify us of when something&amp;#x2019;s happened on the file system\n\n
  • #55: \n
  • #56: \n