SlideShare a Scribd company logo
1 of 49
Download to read offline
ActiveMQ In Action
                Common Problems and Solutions

                                 Bruce Snyder
                                 VMware, Inc.
                             bsnyder@vmware.com


Wednesday, November 16, 11
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?


     • Bonus: Do I need a network of brokers?
     • Bonus: Should I use a master/slave configuration?



Wednesday, November 16, 11
Should I create JMS clients from scratch?




                                             3

Wednesday, November 16, 11
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

Wednesday, November 16, 11
Spring JMS




                                          5

Wednesday, November 16, 11
Spring JMS


                             • JMS Template
                               – Send and receive messages
                                 synchronously


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




                                                                   6

Wednesday, November 16, 11
Spring JMS


                             • JMS Template
                               – Send and receive messages
                                 synchronously


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




                                                                   7

Wednesday, November 16, 11
How do I manage connections efficiently?




                                           8

Wednesday, November 16, 11
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

Wednesday, November 16, 11
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

Wednesday, November 16, 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 property!
     • Consumers are not closed until Session is closed
          – NOTE: Cache strategy uses the JMS selector as a key




                                                                  11

Wednesday, November 16, 11
Quick Tip: Monitor the Broker


     • Q: How can I monitor the message broker while I am
       developing?
     • A: Manually via JMX
     • A: Use the web console (backed by JMX)
     • A: Use the advisory messages
          – Especially powerful
          – http://activemq.apache.org/advisory-message.html




                                                               12

Wednesday, November 16, 11
How do I consume only certain messages?




                                         13

Wednesday, November 16, 11
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




                                                      14

Wednesday, November 16, 11
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 decimal
                 Literals
                             or scientific notation such as 43.3E7,
                             +10.5239
               Identifiers    A header field

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


                                                                        15

Wednesday, November 16, 11
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);




                                                                                     16

Wednesday, November 16, 11
JMS Selectors

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




                                                   17

Wednesday, November 16, 11
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


                                                      18

Wednesday, November 16, 11
Quick Tip: Clearing the DLQ


     • Q: Is there a way to automatically clear messages in the DLQ?
     • A: Use the DiscardingDLQ plugin or create a custom consumer


       <broker brokerName="myBroker” ...>
        <plugins>
         <discardingDLQBrokerPlugin dropAll="true" dropTemporaryTopics="true"
            dropTemporaryQueues="true" />
        </plugins>
       </broker>

       <broker brokerName="myBroker” ...>
        <plugins>
         <discardingDLQBrokerPlugin
          dropOnly="TEST.FOO.[1-9] EXAMPLE.TOPIC"
          reportInverval="5000" />
        </plugins>
       </broker>
                                                                                19

Wednesday, November 16, 11
Why is ActiveMQ is locking up or freezing?




                                                20

Wednesday, November 16, 11
Why is ActiveMQ is locking up or freezing?

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




                                                21

Wednesday, November 16, 11
JVM Memory

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


     • You may need to increase this!




                                                                   22

Wednesday, November 16, 11
Broker Memory

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




                                                       23

Wednesday, November 16, 11
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>

                                                      24

Wednesday, November 16, 11
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




                                                           25

Wednesday, November 16, 11
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" />
   ...




                                                               26

Wednesday, November 16, 11
Producer Flow Control

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

     • NOTE: This setting is enabled by default




                                                        27

Wednesday, November 16, 11
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>


                                                                 28

Wednesday, November 16, 11
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


                                                                   29

Wednesday, November 16, 11
Message Cursor 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>
                                                                 30

Wednesday, November 16, 11
Quick Tip: Rebalancing Clients


     • Q: After restarting one of my message brokers, how can I force
       clients to connect to that broker?
     • A: Enforce a deterministic lifetime on a connection by setting
       the expiryTimeout on the pool of connections
            <bean id="connectionFactory"
             class="org.apache.activemq.pool.PooledConnectionFactory"
             <property name="brokerURL” value="tcp://localhost:61616" />
             <property name="expiryTimeout” value="10000" />
             <property name="connectionFactory">
              <bean id="connectionFactory"
               class="org.apache.activemq.ActiveMQConnectionFactory"
               p:brokerURL="tcp://localhost:61616" />
             </property>
            </bean>



                                                                           31

Wednesday, November 16, 11
Thank You!




         Q&A




Wednesday, November 16, 11
Bonus Material!




                                               #apachecorn
                                                      33

Wednesday, November 16, 11
Do I need a network of brokers?




                                                   34

Wednesday, November 16, 11
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




                                                                                 35

Wednesday, November 16, 11
Store and Forward




                                                 36

Wednesday, November 16, 11
Topology Example




                                                37

Wednesday, November 16, 11
Topology Example




                                                38

Wednesday, November 16, 11
Topology Example




                                                39

Wednesday, November 16, 11
Topology Example




                                                40

Wednesday, November 16, 11
Topology Example




                                                41

Wednesday, November 16, 11
Should I use a master/slave config?




                                                 42

Wednesday, November 16, 11
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?
          – Depends on the type of master/slave




                                                                                 43

Wednesday, November 16, 11
Types of Master/Slave

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




                                                     44

Wednesday, November 16, 11
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




                                                                     45

Wednesday, November 16, 11
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




                                                                             46

Wednesday, November 16, 11
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




                                                                             47

Wednesday, November 16, 11
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




                                                                             48

Wednesday, November 16, 11
Should I use a master/slave config?

     • Are you trying to provide high availability?
          – Then, yes
     • Which one should I use?
          – It depends on your situation




                                                      49

Wednesday, November 16, 11

More Related Content

What's hot

Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQelliando dias
 
Introduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ ArtemisIntroduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ ArtemisYoshimasa Tanabe
 
Spring JMS and ActiveMQ
Spring JMS and ActiveMQSpring JMS and ActiveMQ
Spring JMS and ActiveMQGeert Pante
 
JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers OverviewVadym Lotar
 
Introduction java messaging services
Introduction java messaging servicesIntroduction java messaging services
Introduction java messaging servicesSon Nguyen
 
Jms deep dive [con4864]
Jms deep dive [con4864]Jms deep dive [con4864]
Jms deep dive [con4864]Ryan Cuprak
 
NServiceBus workshop presentation
NServiceBus workshop presentationNServiceBus workshop presentation
NServiceBus workshop presentationTomas Jansson
 
Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)Brian Moon
 
Nimbus project
Nimbus projectNimbus project
Nimbus projectaimas06
 
High Performance Drupal Sites
High Performance Drupal SitesHigh Performance Drupal Sites
High Performance Drupal SitesAbayomi Ayoola
 
Improving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with MemcachedImproving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with MemcachedAcquia
 
Modern Distributed Messaging and RPC
Modern Distributed Messaging and RPCModern Distributed Messaging and RPC
Modern Distributed Messaging and RPCMax Alexejev
 
JUDCon2014-ScalableMessagingWithJBossA-MQ and Apache Camel
JUDCon2014-ScalableMessagingWithJBossA-MQ and Apache CamelJUDCon2014-ScalableMessagingWithJBossA-MQ and Apache Camel
JUDCon2014-ScalableMessagingWithJBossA-MQ and Apache CamelNaveen Raj Balasubramaniam
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaMax Alexejev
 
Yabusame: postcopy live migration for qemu/kvm
Yabusame: postcopy live migration for qemu/kvmYabusame: postcopy live migration for qemu/kvm
Yabusame: postcopy live migration for qemu/kvmIsaku Yamahata
 
NServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architectureNServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architectureMauro Servienti
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBusAdam Fyles
 
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffArchitecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffJAX London
 

What's hot (20)

Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQ
 
Introduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ ArtemisIntroduction to Apache ActiveMQ Artemis
Introduction to Apache ActiveMQ Artemis
 
Spring JMS and ActiveMQ
Spring JMS and ActiveMQSpring JMS and ActiveMQ
Spring JMS and ActiveMQ
 
Mini-Training: Message Brokers
Mini-Training: Message BrokersMini-Training: Message Brokers
Mini-Training: Message Brokers
 
JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers Overview
 
Jms queue
Jms queueJms queue
Jms queue
 
Introduction java messaging services
Introduction java messaging servicesIntroduction java messaging services
Introduction java messaging services
 
Jms deep dive [con4864]
Jms deep dive [con4864]Jms deep dive [con4864]
Jms deep dive [con4864]
 
NServiceBus workshop presentation
NServiceBus workshop presentationNServiceBus workshop presentation
NServiceBus workshop presentation
 
Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)
 
Nimbus project
Nimbus projectNimbus project
Nimbus project
 
High Performance Drupal Sites
High Performance Drupal SitesHigh Performance Drupal Sites
High Performance Drupal Sites
 
Improving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with MemcachedImproving Website Performance and Scalability with Memcached
Improving Website Performance and Scalability with Memcached
 
Modern Distributed Messaging and RPC
Modern Distributed Messaging and RPCModern Distributed Messaging and RPC
Modern Distributed Messaging and RPC
 
JUDCon2014-ScalableMessagingWithJBossA-MQ and Apache Camel
JUDCon2014-ScalableMessagingWithJBossA-MQ and Apache CamelJUDCon2014-ScalableMessagingWithJBossA-MQ and Apache Camel
JUDCon2014-ScalableMessagingWithJBossA-MQ and Apache Camel
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
 
Yabusame: postcopy live migration for qemu/kvm
Yabusame: postcopy live migration for qemu/kvmYabusame: postcopy live migration for qemu/kvm
Yabusame: postcopy live migration for qemu/kvm
 
NServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architectureNServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architecture
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBus
 
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffArchitecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
 

Similar to ActiveMQ In Action - ApacheCon 2011

Post Metasploitation
Post MetasploitationPost Metasploitation
Post Metasploitationegypt
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBusEspen Ekvang
 
Sly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of ProgrammingSly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of ProgrammingStefan Marr
 
Ranker jms implementation
Ranker jms implementationRanker jms implementation
Ranker jms implementationEosSoftware
 
Riak Use Cases : Dissecting The Solutions To Hard Problems
Riak Use Cases : Dissecting The Solutions To Hard ProblemsRiak Use Cases : Dissecting The Solutions To Hard Problems
Riak Use Cases : Dissecting The Solutions To Hard ProblemsAndy Gross
 
High scale flavour
High scale flavourHigh scale flavour
High scale flavourTomas Doran
 
Pulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platformPulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platformMatteo Merli
 

Similar to ActiveMQ In Action - ApacheCon 2011 (9)

Post Metasploitation
Post MetasploitationPost Metasploitation
Post Metasploitation
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBus
 
Sly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of ProgrammingSly and the RoarVM: Exploring the Manycore Future of Programming
Sly and the RoarVM: Exploring the Manycore Future of Programming
 
Jms using j boss
Jms using j bossJms using j boss
Jms using j boss
 
Ranker jms implementation
Ranker jms implementationRanker jms implementation
Ranker jms implementation
 
Apache ActiveMQ
Apache ActiveMQ Apache ActiveMQ
Apache ActiveMQ
 
Riak Use Cases : Dissecting The Solutions To Hard Problems
Riak Use Cases : Dissecting The Solutions To Hard ProblemsRiak Use Cases : Dissecting The Solutions To Hard Problems
Riak Use Cases : Dissecting The Solutions To Hard Problems
 
High scale flavour
High scale flavourHigh scale flavour
High scale flavour
 
Pulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platformPulsar - Distributed pub/sub platform
Pulsar - Distributed pub/sub platform
 

More from Bruce Snyder

Styles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringStyles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringBruce Snyder
 
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 JockeyBruce Snyder
 
Service-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixService-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixBruce Snyder
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a RideBruce Snyder
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixBruce Snyder
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
 
Messaging With ActiveMQ
Messaging With ActiveMQMessaging With ActiveMQ
Messaging With ActiveMQBruce Snyder
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
 

More from 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
 
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
 
Messaging With ActiveMQ
Messaging With ActiveMQMessaging With ActiveMQ
Messaging With ActiveMQ
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 

Recently uploaded

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 WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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...Miguel Araújo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 productivityPrincipled Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

ActiveMQ In Action - ApacheCon 2011

  • 1. ActiveMQ In Action Common Problems and Solutions Bruce Snyder VMware, Inc. bsnyder@vmware.com Wednesday, November 16, 11
  • 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? • Bonus: Do I need a network of brokers? • Bonus: Should I use a master/slave configuration? Wednesday, November 16, 11
  • 3. Should I create JMS clients from scratch? 3 Wednesday, November 16, 11
  • 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 Wednesday, November 16, 11
  • 5. Spring JMS 5 Wednesday, November 16, 11
  • 6. Spring JMS • JMS Template – Send and receive messages synchronously • Message Listener Container – Receive messages asynchronously – Message-Driven POJOs (MDPs) 6 Wednesday, November 16, 11
  • 7. Spring JMS • JMS Template – Send and receive messages synchronously • Message Listener Container – Receive messages asynchronously – Message-Driven POJOs (MDPs) 7 Wednesday, November 16, 11
  • 8. How do I manage connections efficiently? 8 Wednesday, November 16, 11
  • 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 Wednesday, November 16, 11
  • 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 Wednesday, November 16, 11
  • 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 property! • Consumers are not closed until Session is closed – NOTE: Cache strategy uses the JMS selector as a key 11 Wednesday, November 16, 11
  • 12. Quick Tip: Monitor the Broker • Q: How can I monitor the message broker while I am developing? • A: Manually via JMX • A: Use the web console (backed by JMX) • A: Use the advisory messages – Especially powerful – http://activemq.apache.org/advisory-message.html 12 Wednesday, November 16, 11
  • 13. How do I consume only certain messages? 13 Wednesday, November 16, 11
  • 14. 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 14 Wednesday, November 16, 11
  • 15. 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 decimal Literals or scientific notation such as 43.3E7, +10.5239 Identifiers A header field AND, OR, LIKE, BETWEEN, =, <>, <, >, Operators <=, =>, +, =, *, /, IS NULL, IS NOT NULL 15 Wednesday, November 16, 11
  • 16. 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); 16 Wednesday, November 16, 11
  • 17. JMS Selectors • Very powerful, but like a sharp knife • Applied to every message on a destination – Can cause unnecessary overhead 17 Wednesday, November 16, 11
  • 18. 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 18 Wednesday, November 16, 11
  • 19. Quick Tip: Clearing the DLQ • Q: Is there a way to automatically clear messages in the DLQ? • A: Use the DiscardingDLQ plugin or create a custom consumer <broker brokerName="myBroker” ...> <plugins> <discardingDLQBrokerPlugin dropAll="true" dropTemporaryTopics="true" dropTemporaryQueues="true" /> </plugins> </broker> <broker brokerName="myBroker” ...> <plugins> <discardingDLQBrokerPlugin dropOnly="TEST.FOO.[1-9] EXAMPLE.TOPIC" reportInverval="5000" /> </plugins> </broker> 19 Wednesday, November 16, 11
  • 20. Why is ActiveMQ is locking up or freezing? 20 Wednesday, November 16, 11
  • 21. Why is ActiveMQ is locking up or freezing? • JVM memory • Broker memory • Prefetch limit • Producer flow control • Message cursors 21 Wednesday, November 16, 11
  • 22. JVM Memory • ActiveMQ start script – In 5.4.x, JVM is given 256mb of memory (min and max) • You may need to increase this! 22 Wednesday, November 16, 11
  • 23. Broker Memory • ActiveMQ controls how much memory it can use • Will not automatically use all the JVM memory • Configurable but commented out by default 23 Wednesday, November 16, 11
  • 24. 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> 24 Wednesday, November 16, 11
  • 25. 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 25 Wednesday, November 16, 11
  • 26. 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" /> ... 26 Wednesday, November 16, 11
  • 27. Producer Flow Control • Prevents producer from flooding broker • If memory exceeds limit, a producer will be paused • NOTE: This setting is enabled by default 27 Wednesday, November 16, 11
  • 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"> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> ... </broker> 28 Wednesday, November 16, 11
  • 29. 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 29 Wednesday, November 16, 11
  • 30. Message Cursor 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> 30 Wednesday, November 16, 11
  • 31. Quick Tip: Rebalancing Clients • Q: After restarting one of my message brokers, how can I force clients to connect to that broker? • A: Enforce a deterministic lifetime on a connection by setting the expiryTimeout on the pool of connections <bean id="connectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" <property name="brokerURL” value="tcp://localhost:61616" /> <property name="expiryTimeout” value="10000" /> <property name="connectionFactory"> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="tcp://localhost:61616" /> </property> </bean> 31 Wednesday, November 16, 11
  • 32. Thank You! Q&A Wednesday, November 16, 11
  • 33. Bonus Material! #apachecorn 33 Wednesday, November 16, 11
  • 34. Do I need a network of brokers? 34 Wednesday, November 16, 11
  • 35. 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 35 Wednesday, November 16, 11
  • 36. Store and Forward 36 Wednesday, November 16, 11
  • 37. Topology Example 37 Wednesday, November 16, 11
  • 38. Topology Example 38 Wednesday, November 16, 11
  • 39. Topology Example 39 Wednesday, November 16, 11
  • 40. Topology Example 40 Wednesday, November 16, 11
  • 41. Topology Example 41 Wednesday, November 16, 11
  • 42. Should I use a master/slave config? 42 Wednesday, November 16, 11
  • 43. 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? – Depends on the type of master/slave 43 Wednesday, November 16, 11
  • 44. Types of Master/Slave • Shared nothing master/slave • Shared storage master/slave – Shared database – Shared file system 44 Wednesday, November 16, 11
  • 45. 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 45 Wednesday, November 16, 11
  • 46. 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 46 Wednesday, November 16, 11
  • 47. 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 47 Wednesday, November 16, 11
  • 48. 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 48 Wednesday, November 16, 11
  • 49. Should I use a master/slave config? • Are you trying to provide high availability? – Then, yes • Which one should I use? – It depends on your situation 49 Wednesday, November 16, 11