SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
ActiveMQ in Action:
    Common Problems and Solutions
    Bruce Snyder, Senior Software Engineer, SpringSource/VMware




Friday, July 8, 2011
Common Questions

    •    Should I create my JMS clients from scratch?
    •    How do I manage connections efficiently?
    •    How do I consume only certain messages?
    •    Why is ActiveMQ locking up or freezing?
    •    Do I need a network of brokers?
    •    Should I use a master/slave configuration?




Friday, July 8, 2011
Should I create JMS clients from scratch?




                                                3

Friday, July 8, 2011
Should I create JMS clients from scratch?

    • Question:
           – Would you create a HTTP client from scratch?
           – Would you create a SMTP client from scratch?


    • Answer:
           – Sometimes, but mostly no


    • Solution:
           – Use Spring JMS




                                                            4

Friday, July 8, 2011
Spring JMS




                       5

Friday, July 8, 2011
Spring JMS


                       • JMS Template
                          – Send and receive messages
                            synchronously

                       • Message Listener Container
                          – Receive messages asynchronously
                          – Message-Driven POJOs (MDPs)




                                                              6

Friday, July 8, 2011
Spring JMS


                       • JMS Template
                         – Send and receive messages
                           synchronously

                       • Message Listener Container
                         – Receive messages asynchronously
                         – Message-Driven POJOs (MDPs)




                                                             7

Friday, July 8, 2011
How do I manage connections efficiently?




                                               8

Friday, July 8, 2011
How do I manage connections efficiently?

    • JMS connections are expensive to constantly create and
      destroy
    • Create a group that never closes, i.e., pooling

    • Solutions:
           – ActiveMQ PooledConnectionFactory
           – Spring CachingConnectionFactory




                                                               9

Friday, July 8, 2011
ActiveMQ PooledConnectionFactory

    • Based on Apache Commons Pool
           – Generic object pooling framework from the ASF
    • Highly configurable
           – Instantiate your own custom GenericObjectPool
    • Could be improved
           – Upon hitting pool limit, grow the pool instead of blocking
           – Throw exception when the pool is exhausted
    • Caches JMS Sessions and MessageProducers




                                                                          10

Friday, July 8, 2011
Spring CachingConnectionFactory

    • Based on Spring SingleConnectionFactory
           – Ignores calls to Connection.close()
    • Caches JMS Sessions and MessageProducers
    • By default only one session is cached
           – Increase the sessionCacheSize!
    • Consumers are not closed until Session is closed
           – NOTE: Cache strategy uses the JMS selector as a key




                                                                   11

Friday, July 8, 2011
How do I consume only certain messages?




                                          12

Friday, July 8, 2011
How do I consume only certain messages?

    • ActiveMQ is for sending and receiving events
    • ActiveMQ is NOT a message store

    • Solutions:
           – Use message selectors
           – Correct application design




                                                     13

Friday, July 8, 2011
JMS Selectors

    •    Allows a client to filter messages from a destination
    •    Filters message headers only, not payload
    •    Conditional expressions using a subset of SQL
    •    Provide boolean evaluation of message headers

                                  Booleans TRUE/FALSE; numbers
                                  such as 5, -10, +34; numbers with
                       Literals
                                  decimal or scientific notation such as
                                  43.3E7, +10.5239

                  Identifiers     A header field

                                  AND, OR, LIKE, BETWEEN, =, <>, <,
                  Operators       >, <=, =>, +, =, *, /, IS NULL, IS
                                  NOT NULL

                                                                           14

Friday, July 8, 2011
JMS Selector Examples

         // Select messages with a header named symbol whose value is APPL
         String selector = "symbol = ʻAPPLʼ";

         // Create a consumer that only receives messages about Apple Computer stock
         MessageConsumer consumer =
                 session.createConsumer(someDestination, selector);



         // Select messages with a header named symbol whose value is APPL
         // and with a header named price that is greater than the previous price
         String selector = "symbol = ʻAPPLʼ AND price > " + getPreviousPrice();

         // Create a consumer that only receives messages about Apple Computer stock
         // that has increased in price
         MessageConsumer consumer =
                  session.createConsumer(someDestination, selector);




                                                                                       15

Friday, July 8, 2011
JMS Selectors

    • Very powerful, but like a sharp knife
    • Applied to every message on a destination
           – Can cause unnecessary overhead




                                                  16

Friday, July 8, 2011
Correct Application Design

    • ActiveMQ is for sending and receiving events
    • ActiveMQ is NOT a message store

    • Phase one, consume the messages
           – Lightweight processing
    • Phase two, conduct further processing
           – Heavyweight processing

    • I.e., a proper service-oriented architecture




                                                     17

Friday, July 8, 2011
Why is ActiveMQ is locking up or freezing?




                                             18

Friday, July 8, 2011
Why is ActiveMQ is locking up or freezing?

    •    JVM memory
    •    Broker memory
    •    Prefetch limit
    •    Producer flow control
    •    Message cursors




                                             19

Friday, July 8, 2011
JVM Memory

    • ActiveMQ start script
           – As of 5.4.x JVM is given 256mb of memory (min and max)


    • You may need to increase this!




                                                                      20

Friday, July 8, 2011
Broker Memory

    • ActiveMQ controls how much memory it can use
    • Will not automatically use all the JVM memory
    • Configurable but commented out by default




                                                      21

Friday, July 8, 2011
Broker Memory Example

                  <broker brokerName="myBroker” ...>
                  ...
                    <systemUsage>
                      <systemUsage>
                       <memoryUsage>
                        <memoryUsage limit="64 mb” />
                       </memoryUsage>
                       <storeUsage>
                        <storeUsage limit="100 gb" />
                       </storeUsage>
                       <tempUsage>
                        <tempUsage limit="10 gb" />
                       </tempUsage>
                      </systemUsage>
                    </systemUsage>
                  ...
                  </broker>

                                                        22

Friday, July 8, 2011
Prefetch Limit

    • Prevents a consumer from being flooded with messages
    • Applied on a per client basis

    • Incorrect prefetch limit + slow consumer =
      messages remain in a queue unconsumed

    • Results in some consumers being starved of messages

    • NOTE: Be careful with connection pools




                                                             23

Friday, July 8, 2011
Prefetch Limit Example


   ...
     <bean id="connectionFactory"
       class="org.apache.activemq.ActiveMQConnectionFactory"
       p:brokerURL="tcp://localhost:61616"
       p:prefetchPolicy-ref="prefetchPolicy"/>

     <bean id="prefetchPolicy"
       class="org.apache.activemq.ActiveMQPrefetchPolicy"
       p:queuePrefetch="1" />
   ...




                                                               24

Friday, July 8, 2011
Producer Flow Control

    • Prevents producer from flooding broker
    • If memory exceeds limit, a producer will be paused

    • NOTE: This setting is enabled by default




                                                           25

Friday, July 8, 2011
Broker Memory Example

          <broker brokerName="myBroker” ...>
          ...
          <destinationPolicy>
            <policyMap>
              <policyEntries>
               <policyEntry topic=">" producerFlowControl="true"
                memoryLimit="10mb">
                <pendingSubscriberPolicy>
                 <vmCursor />
                </pendingSubscriberPolicy>
               </policyEntry>
               <policyEntry queue=">" producerFlowControl="true"
                memoryLimit="10mb">
               </policyEntry>
              </policyEntries>
            </policyMap>
          </destinationPolicy>
          ...
          </broker>


                                                                   26

Friday, July 8, 2011
Message Cursors

    • Only so many messages can be held in memory
    • Message cursors provide a configurable message paging

    • Two types of cursors
           – VM cursors
                 • Holds only message reference in memory
           – File cursors
                 • Flushes both message and reference to disk


    • http://activemq.apache.org/how-do-i-configure-activemq-
      to-hold-100s-of-millions-of-queue-messages-.html


                                                                27

Friday, July 8, 2011
Broker Memory Example

          <broker brokerName="myBroker” ...>
          ...
          <destinationPolicy>
            <policyMap>
              <policyEntries>
               <policyEntry topic=">" producerFlowControl="true"
                memoryLimit="10mb">
                <pendingSubscriberPolicy>
                 <vmCursor />
                </pendingSubscriberPolicy>
               </policyEntry>
               <policyEntry queue=">" producerFlowControl="true"
                memoryLimit="10mb">
                <pendingQueuePolicy>
                 <fileQueueCursor />
                </pendingQueuePolicy>
               </policyEntry>
              </policyEntries>
            </policyMap>
          </destinationPolicy>
          ...
          </broker>                                                28

Friday, July 8, 2011
Do I need a network of brokers?




                                      29

Friday, July 8, 2011
Do I need a network of brokers?

    • What is a network of brokers?
           – Clustered ActiveMQ instances
    • How are they clustered?
           – They pass messages between broker instances
           – Send a message to one broker, consume the message from
             a different broker
    • Where might this be useful?
           – Situations where a centralized broker is not suitable
    • How does this work?
           – Using store and forward




                                                                     30

Friday, July 8, 2011
Store and Forward




                        31

Friday, July 8, 2011
Topology Example




                       32

Friday, July 8, 2011
Topology Example




                       33

Friday, July 8, 2011
Topology Example




                       34

Friday, July 8, 2011
Topology Example




                       35

Friday, July 8, 2011
Topology Example




                       36

Friday, July 8, 2011
Should I use a master/slave config?




                                          37

Friday, July 8, 2011
Should I use a master/slave config?

    • What is a master/slave configuration?
           – It helps to provide high availability for ActiveMQ
    • What does that mean?
           – ActiveMQ brokers are configured for warm failover
           – If one broker fails or becomes unreachable, another one
             takes over
    • Where might this be useful?
           – In situations that need highly available message brokers
    • How does this work?
           –




                                                                        38

Friday, July 8, 2011
Types of Master/Slave

    • Shared nothing master/slave
    • Shared storage master/slave
           – Shared database
           – Shared file system




                                    39

Friday, July 8, 2011
Shared Nothing Master/Slave

    • Sometimes called pure master/slave
    • Uses a fully replicated data store
           – Does not depend on database or file system
    • Slave broker consumes all message states from the
      Master broker (messages, acks, tx states)
    • Slave does not start any networking or transport
      connectors
    • Master broker will only respond to client when a message
      exchange has been successfully passed to the slave
      broker



                                                             40

Friday, July 8, 2011
Shared Nothing Master/Slave

    • If the master fails, the slave optionally has two modes of
      operation:
           1. Start up all it’s network and transport connectors
                 • All clients connected to failed Master resume on Slave
           2. Close down completely
                 • Slave is simply used to duplicate state from Master


    • Clients should use failover transport:


     failover://(tcp://masterhost:61616, tcp://slavehost:61616)?randomize=false




                                                                             41

Friday, July 8, 2011
Shared Database Master/Slave

    •     Uses tables in a relational database to store data
    •     No restriction on the number of brokers
    •     Simple configuration (JDBC URL)
    •     Clustered database mitigates single point of failure
    •     One master selected at random

    • Clients should use failover transport:

        failover://(tcp://masterhost:61616, tcp://slavehost:61616)?randomize=false




                                                                                42

Friday, July 8, 2011
Shared File System Master/Slave

    •     Utilizes a directory on a shared file system to store data
    •     No restriction on number of brokers
    •     Simple configuration (point to the data dir)
    •     Shared file system mitigates single point of failure
    •     One master selected at random

    • Clients should use failover transport:

        failover://(tcp://masterhost:61616, tcp://slavehost:61616)?randomize=false




                                                                                43

Friday, July 8, 2011
Thank You!




           Q&A




Friday, July 8, 2011

Contenu connexe

Tendances

[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...
[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...
[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...
Funada Yasunobu
 
Ebs 12.2 con9021_pdf_9021_0001
Ebs 12.2 con9021_pdf_9021_0001Ebs 12.2 con9021_pdf_9021_0001
Ebs 12.2 con9021_pdf_9021_0001
jucaab
 

Tendances (20)

RabbitMQ vs Apache Kafka - Part 1
RabbitMQ vs Apache Kafka - Part 1RabbitMQ vs Apache Kafka - Part 1
RabbitMQ vs Apache Kafka - Part 1
 
JMS - Java Messaging Service
JMS - Java Messaging ServiceJMS - Java Messaging Service
JMS - Java Messaging Service
 
RabbitMQ.ppt
RabbitMQ.pptRabbitMQ.ppt
RabbitMQ.ppt
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introduction
 
Kafka presentation
Kafka presentationKafka presentation
Kafka presentation
 
Apache Kafka – (Pattern and) Anti-Pattern
Apache Kafka – (Pattern and) Anti-PatternApache Kafka – (Pattern and) Anti-Pattern
Apache Kafka – (Pattern and) Anti-Pattern
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
 
Integrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalIntegrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere Portal
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and Kafka
 
[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...
[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...
[DB tech showcase Tokyo 2015] B37 :オンプレミスからAWS上のSAP HANAまで高信頼DBシステム構築にHAクラスタリ...
 
Spring AOP in Nutshell
Spring AOP in Nutshell Spring AOP in Nutshell
Spring AOP in Nutshell
 
oracle service bus
oracle service busoracle service bus
oracle service bus
 
Ebs 12.2 con9021_pdf_9021_0001
Ebs 12.2 con9021_pdf_9021_0001Ebs 12.2 con9021_pdf_9021_0001
Ebs 12.2 con9021_pdf_9021_0001
 
Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)
 
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to KnowOracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
 
IBM MQ cloud architecture blueprint
IBM MQ cloud architecture blueprintIBM MQ cloud architecture blueprint
IBM MQ cloud architecture blueprint
 
10 Tips for Successful 12.2 Upgrade
10 Tips for Successful 12.2 Upgrade10 Tips for Successful 12.2 Upgrade
10 Tips for Successful 12.2 Upgrade
 
Managing multiple event types in a single topic with Schema Registry | Bill B...
Managing multiple event types in a single topic with Schema Registry | Bill B...Managing multiple event types in a single topic with Schema Registry | Bill B...
Managing multiple event types in a single topic with Schema Registry | Bill B...
 
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once SemanticsPragmatic Guide to Apache Kafka®'s Exactly Once Semantics
Pragmatic Guide to Apache Kafka®'s Exactly Once Semantics
 

En vedette

Messaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQMessaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQ
dejanb
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQ
Bruce Snyder
 
Apache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in actionApache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in action
dejanb
 
Apache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelApache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache Camel
Omi Om
 
Enterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQEnterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQ
Rob Davies
 
Dopplr: It's made of messages - Matt Biddulph
Dopplr: It's made of messages - Matt BiddulphDopplr: It's made of messages - Matt Biddulph
Dopplr: It's made of messages - Matt Biddulph
Carsonified Team
 
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
 

En vedette (20)

Messaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQMessaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQ
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQ
 
Apache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in actionApache ActiveMQ - Enterprise messaging in action
Apache ActiveMQ - Enterprise messaging in action
 
Active MQ
Active MQActive MQ
Active MQ
 
Apache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache CamelApache ActiveMQ and Apache Camel
Apache ActiveMQ and Apache Camel
 
Enterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQEnterprise Integration Patterns with ActiveMQ
Enterprise Integration Patterns with ActiveMQ
 
Dopplr: It's made of messages - Matt Biddulph
Dopplr: It's made of messages - Matt BiddulphDopplr: It's made of messages - Matt Biddulph
Dopplr: It's made of messages - Matt Biddulph
 
Active mq Installation and Master Slave setup
Active mq Installation and Master Slave setupActive mq Installation and Master Slave setup
Active mq Installation and Master Slave setup
 
Introduction to ActiveMQ Apollo
Introduction to ActiveMQ ApolloIntroduction to ActiveMQ Apollo
Introduction to ActiveMQ Apollo
 
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
 
ActiveMQ 5.9.x new features
ActiveMQ 5.9.x new featuresActiveMQ 5.9.x new features
ActiveMQ 5.9.x new features
 
Polyglot Messaging with Apache ActiveMQ
Polyglot Messaging with Apache ActiveMQPolyglot Messaging with Apache ActiveMQ
Polyglot Messaging with Apache ActiveMQ
 
IBM MQ vs Apache ActiveMQ
IBM MQ vs Apache ActiveMQIBM MQ vs Apache ActiveMQ
IBM MQ vs Apache ActiveMQ
 
Deploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse FabricDeploying FuseMQ with Fuse Fabric
Deploying FuseMQ with Fuse Fabric
 
ам3. свойства и основные понятия archimate
ам3. свойства и основные понятия archimateам3. свойства и основные понятия archimate
ам3. свойства и основные понятия archimate
 
Enterprise mobility
Enterprise mobilityEnterprise mobility
Enterprise mobility
 
Server load balancer ppt
Server load balancer pptServer load balancer ppt
Server load balancer ppt
 
Mcollective orchestration tool 소개
Mcollective orchestration tool 소개Mcollective orchestration tool 소개
Mcollective orchestration tool 소개
 
A Practical Guide for Selecting an Enterprise Messaging Platforms
A Practical Guide for Selecting an Enterprise Messaging PlatformsA Practical Guide for Selecting an Enterprise Messaging Platforms
A Practical Guide for Selecting an Enterprise Messaging Platforms
 
모바일 개발 트랜드
모바일 개발 트랜드모바일 개발 트랜드
모바일 개발 트랜드
 

Similaire à ActiveMQ In Action

ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011
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
 
Application Profiling for Memory and Performance
Application Profiling for Memory and PerformanceApplication Profiling for Memory and Performance
Application Profiling for Memory and Performance
WSO2
 
Introduction to Web Application Clustering
Introduction to Web Application ClusteringIntroduction to Web Application Clustering
Introduction to Web Application Clustering
Piyush Katariya
 

Similaire à ActiveMQ In Action (20)

ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011
 
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
 
MongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema DesignMongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema Design
 
Direct memory jugl-2012.03.08
Direct memory jugl-2012.03.08Direct memory jugl-2012.03.08
Direct memory jugl-2012.03.08
 
Enterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMSEnterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMS
 
Application Profiling for Memory and Performance
Application Profiling for Memory and PerformanceApplication Profiling for Memory and Performance
Application Profiling for Memory and Performance
 
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan GallimoreJava EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
Java EE | Apache TomEE - Java EE Web Profile on Tomcat | Jonathan Gallimore
 
Application Profiling for Memory and Performance
Application Profiling for Memory and PerformanceApplication Profiling for Memory and Performance
Application Profiling for Memory and Performance
 
Membase Meetup - San Diego
Membase Meetup - San DiegoMembase Meetup - San Diego
Membase Meetup - San Diego
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Webinar: StorPool and WHIR - better storage, better business
Webinar: StorPool and WHIR - better storage, better businessWebinar: StorPool and WHIR - better storage, better business
Webinar: StorPool and WHIR - better storage, better business
 
Introduction to Web Application Clustering
Introduction to Web Application ClusteringIntroduction to Web Application Clustering
Introduction to Web Application Clustering
 
Jms deep dive [con4864]
Jms deep dive [con4864]Jms deep dive [con4864]
Jms deep dive [con4864]
 
Do we need JMS in 21st century?
Do we need JMS in 21st century?Do we need JMS in 21st century?
Do we need JMS in 21st century?
 
Cassandra 2.0 better, faster, stronger
Cassandra 2.0   better, faster, strongerCassandra 2.0   better, faster, stronger
Cassandra 2.0 better, faster, stronger
 
Jms using j boss
Jms using j bossJms using j boss
Jms using j boss
 
Cassandra Community Webinar | Cassandra 2.0 - Better, Faster, Stronger
Cassandra Community Webinar | Cassandra 2.0 - Better, Faster, StrongerCassandra Community Webinar | Cassandra 2.0 - Better, Faster, Stronger
Cassandra Community Webinar | Cassandra 2.0 - Better, Faster, Stronger
 
La vita nella corsia di sorpasso; A tutta velocità, XPages!
La vita nella corsia di sorpasso; A tutta velocità, XPages!La vita nella corsia di sorpasso; A tutta velocità, XPages!
La vita nella corsia di sorpasso; A tutta velocità, XPages!
 
Life in the Fast Lane: Full Speed XPages!, #dd13
Life in the Fast Lane: Full Speed XPages!, #dd13Life in the Fast Lane: Full Speed XPages!, #dd13
Life in the Fast Lane: Full Speed XPages!, #dd13
 
[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions
 

Plus de Bruce Snyder

Plus de Bruce Snyder (9)

Styles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringStyles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using Spring
 
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
 
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
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a Ride
 
EIP In Practice
EIP In PracticeEIP In Practice
EIP In Practice
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
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
 

Dernier

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

Dernier (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 

ActiveMQ In Action

  • 1. ActiveMQ in Action: Common Problems and Solutions Bruce Snyder, Senior Software Engineer, SpringSource/VMware Friday, July 8, 2011
  • 2. Common Questions • Should I create my JMS clients from scratch? • How do I manage connections efficiently? • How do I consume only certain messages? • Why is ActiveMQ locking up or freezing? • Do I need a network of brokers? • Should I use a master/slave configuration? Friday, July 8, 2011
  • 3. Should I create JMS clients from scratch? 3 Friday, July 8, 2011
  • 4. Should I create JMS clients from scratch? • Question: – Would you create a HTTP client from scratch? – Would you create a SMTP client from scratch? • Answer: – Sometimes, but mostly no • Solution: – Use Spring JMS 4 Friday, July 8, 2011
  • 5. Spring JMS 5 Friday, July 8, 2011
  • 6. Spring JMS • JMS Template – Send and receive messages synchronously • Message Listener Container – Receive messages asynchronously – Message-Driven POJOs (MDPs) 6 Friday, July 8, 2011
  • 7. Spring JMS • JMS Template – Send and receive messages synchronously • Message Listener Container – Receive messages asynchronously – Message-Driven POJOs (MDPs) 7 Friday, July 8, 2011
  • 8. How do I manage connections efficiently? 8 Friday, July 8, 2011
  • 9. How do I manage connections efficiently? • JMS connections are expensive to constantly create and destroy • Create a group that never closes, i.e., pooling • Solutions: – ActiveMQ PooledConnectionFactory – Spring CachingConnectionFactory 9 Friday, July 8, 2011
  • 10. ActiveMQ PooledConnectionFactory • Based on Apache Commons Pool – Generic object pooling framework from the ASF • Highly configurable – Instantiate your own custom GenericObjectPool • Could be improved – Upon hitting pool limit, grow the pool instead of blocking – Throw exception when the pool is exhausted • Caches JMS Sessions and MessageProducers 10 Friday, July 8, 2011
  • 11. Spring CachingConnectionFactory • Based on Spring SingleConnectionFactory – Ignores calls to Connection.close() • Caches JMS Sessions and MessageProducers • By default only one session is cached – Increase the sessionCacheSize! • Consumers are not closed until Session is closed – NOTE: Cache strategy uses the JMS selector as a key 11 Friday, July 8, 2011
  • 12. How do I consume only certain messages? 12 Friday, July 8, 2011
  • 13. How do I consume only certain messages? • ActiveMQ is for sending and receiving events • ActiveMQ is NOT a message store • Solutions: – Use message selectors – Correct application design 13 Friday, July 8, 2011
  • 14. JMS Selectors • Allows a client to filter messages from a destination • Filters message headers only, not payload • Conditional expressions using a subset of SQL • Provide boolean evaluation of message headers Booleans TRUE/FALSE; numbers such as 5, -10, +34; numbers with Literals decimal or scientific notation such as 43.3E7, +10.5239 Identifiers A header field AND, OR, LIKE, BETWEEN, =, <>, <, Operators >, <=, =>, +, =, *, /, IS NULL, IS NOT NULL 14 Friday, July 8, 2011
  • 15. JMS Selector Examples // Select messages with a header named symbol whose value is APPL String selector = "symbol = ʻAPPLʼ"; // Create a consumer that only receives messages about Apple Computer stock MessageConsumer consumer = session.createConsumer(someDestination, selector); // Select messages with a header named symbol whose value is APPL // and with a header named price that is greater than the previous price String selector = "symbol = ʻAPPLʼ AND price > " + getPreviousPrice(); // Create a consumer that only receives messages about Apple Computer stock // that has increased in price MessageConsumer consumer = session.createConsumer(someDestination, selector); 15 Friday, July 8, 2011
  • 16. JMS Selectors • Very powerful, but like a sharp knife • Applied to every message on a destination – Can cause unnecessary overhead 16 Friday, July 8, 2011
  • 17. Correct Application Design • ActiveMQ is for sending and receiving events • ActiveMQ is NOT a message store • Phase one, consume the messages – Lightweight processing • Phase two, conduct further processing – Heavyweight processing • I.e., a proper service-oriented architecture 17 Friday, July 8, 2011
  • 18. Why is ActiveMQ is locking up or freezing? 18 Friday, July 8, 2011
  • 19. Why is ActiveMQ is locking up or freezing? • JVM memory • Broker memory • Prefetch limit • Producer flow control • Message cursors 19 Friday, July 8, 2011
  • 20. JVM Memory • ActiveMQ start script – As of 5.4.x JVM is given 256mb of memory (min and max) • You may need to increase this! 20 Friday, July 8, 2011
  • 21. Broker Memory • ActiveMQ controls how much memory it can use • Will not automatically use all the JVM memory • Configurable but commented out by default 21 Friday, July 8, 2011
  • 22. Broker Memory Example <broker brokerName="myBroker” ...> ... <systemUsage> <systemUsage> <memoryUsage> <memoryUsage limit="64 mb” /> </memoryUsage> <storeUsage> <storeUsage limit="100 gb" /> </storeUsage> <tempUsage> <tempUsage limit="10 gb" /> </tempUsage> </systemUsage> </systemUsage> ... </broker> 22 Friday, July 8, 2011
  • 23. Prefetch Limit • Prevents a consumer from being flooded with messages • Applied on a per client basis • Incorrect prefetch limit + slow consumer = messages remain in a queue unconsumed • Results in some consumers being starved of messages • NOTE: Be careful with connection pools 23 Friday, July 8, 2011
  • 24. Prefetch Limit Example ... <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="tcp://localhost:61616" p:prefetchPolicy-ref="prefetchPolicy"/> <bean id="prefetchPolicy" class="org.apache.activemq.ActiveMQPrefetchPolicy" p:queuePrefetch="1" /> ... 24 Friday, July 8, 2011
  • 25. Producer Flow Control • Prevents producer from flooding broker • If memory exceeds limit, a producer will be paused • NOTE: This setting is enabled by default 25 Friday, July 8, 2011
  • 26. Broker Memory Example <broker brokerName="myBroker” ...> ... <destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">" producerFlowControl="true" memoryLimit="10mb"> <pendingSubscriberPolicy> <vmCursor /> </pendingSubscriberPolicy> </policyEntry> <policyEntry queue=">" producerFlowControl="true" memoryLimit="10mb"> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> ... </broker> 26 Friday, July 8, 2011
  • 27. Message Cursors • Only so many messages can be held in memory • Message cursors provide a configurable message paging • Two types of cursors – VM cursors • Holds only message reference in memory – File cursors • Flushes both message and reference to disk • http://activemq.apache.org/how-do-i-configure-activemq- to-hold-100s-of-millions-of-queue-messages-.html 27 Friday, July 8, 2011
  • 28. Broker Memory Example <broker brokerName="myBroker” ...> ... <destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">" producerFlowControl="true" memoryLimit="10mb"> <pendingSubscriberPolicy> <vmCursor /> </pendingSubscriberPolicy> </policyEntry> <policyEntry queue=">" producerFlowControl="true" memoryLimit="10mb"> <pendingQueuePolicy> <fileQueueCursor /> </pendingQueuePolicy> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> ... </broker> 28 Friday, July 8, 2011
  • 29. Do I need a network of brokers? 29 Friday, July 8, 2011
  • 30. Do I need a network of brokers? • What is a network of brokers? – Clustered ActiveMQ instances • How are they clustered? – They pass messages between broker instances – Send a message to one broker, consume the message from a different broker • Where might this be useful? – Situations where a centralized broker is not suitable • How does this work? – Using store and forward 30 Friday, July 8, 2011
  • 31. Store and Forward 31 Friday, July 8, 2011
  • 32. Topology Example 32 Friday, July 8, 2011
  • 33. Topology Example 33 Friday, July 8, 2011
  • 34. Topology Example 34 Friday, July 8, 2011
  • 35. Topology Example 35 Friday, July 8, 2011
  • 36. Topology Example 36 Friday, July 8, 2011
  • 37. Should I use a master/slave config? 37 Friday, July 8, 2011
  • 38. Should I use a master/slave config? • What is a master/slave configuration? – It helps to provide high availability for ActiveMQ • What does that mean? – ActiveMQ brokers are configured for warm failover – If one broker fails or becomes unreachable, another one takes over • Where might this be useful? – In situations that need highly available message brokers • How does this work? – 38 Friday, July 8, 2011
  • 39. Types of Master/Slave • Shared nothing master/slave • Shared storage master/slave – Shared database – Shared file system 39 Friday, July 8, 2011
  • 40. Shared Nothing Master/Slave • Sometimes called pure master/slave • Uses a fully replicated data store – Does not depend on database or file system • Slave broker consumes all message states from the Master broker (messages, acks, tx states) • Slave does not start any networking or transport connectors • Master broker will only respond to client when a message exchange has been successfully passed to the slave broker 40 Friday, July 8, 2011
  • 41. Shared Nothing Master/Slave • If the master fails, the slave optionally has two modes of operation: 1. Start up all it’s network and transport connectors • All clients connected to failed Master resume on Slave 2. Close down completely • Slave is simply used to duplicate state from Master • Clients should use failover transport: failover://(tcp://masterhost:61616, tcp://slavehost:61616)?randomize=false 41 Friday, July 8, 2011
  • 42. Shared Database Master/Slave • Uses tables in a relational database to store data • No restriction on the number of brokers • Simple configuration (JDBC URL) • Clustered database mitigates single point of failure • One master selected at random • Clients should use failover transport: failover://(tcp://masterhost:61616, tcp://slavehost:61616)?randomize=false 42 Friday, July 8, 2011
  • 43. Shared File System Master/Slave • Utilizes a directory on a shared file system to store data • No restriction on number of brokers • Simple configuration (point to the data dir) • Shared file system mitigates single point of failure • One master selected at random • Clients should use failover transport: failover://(tcp://masterhost:61616, tcp://slavehost:61616)?randomize=false 43 Friday, July 8, 2011
  • 44. Thank You! Q&A Friday, July 8, 2011