SlideShare una empresa de Scribd logo
1 de 44
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers Overview
Vadym Lotar
 
Exchange 2013 Architecture Details
Exchange 2013 Architecture DetailsExchange 2013 Architecture Details
Exchange 2013 Architecture Details
Huy Phạm
 

La actualidad más candente (20)

JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers Overview
 
Oracle Enterprise Manager
Oracle Enterprise ManagerOracle Enterprise Manager
Oracle Enterprise Manager
 
Security and compliance in Office 365 -Part 1
Security and compliance in Office 365 -Part 1Security and compliance in Office 365 -Part 1
Security and compliance in Office 365 -Part 1
 
Introducing Oracle Audit Vault and Database Firewall
Introducing Oracle Audit Vault and Database FirewallIntroducing Oracle Audit Vault and Database Firewall
Introducing Oracle Audit Vault and Database Firewall
 
INTEGRATE 2022 - Data Mapping in the Microsoft Cloud
INTEGRATE 2022 - Data Mapping in the Microsoft CloudINTEGRATE 2022 - Data Mapping in the Microsoft Cloud
INTEGRATE 2022 - Data Mapping in the Microsoft Cloud
 
Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?Free Load Testing Tools for Oracle Database – Which One Do I Use?
Free Load Testing Tools for Oracle Database – Which One Do I Use?
 
Exchange 2013 Architecture Details
Exchange 2013 Architecture DetailsExchange 2013 Architecture Details
Exchange 2013 Architecture Details
 
Oracle Managed File Transfer
Oracle Managed File TransferOracle Managed File Transfer
Oracle Managed File Transfer
 
Digital reference architecture in hybrid cloud
Digital reference architecture in hybrid cloudDigital reference architecture in hybrid cloud
Digital reference architecture in hybrid cloud
 
What is Office 365 | Benifits of Office 365 | Learn Office 365
What is Office 365 | Benifits of Office 365 | Learn Office 365What is Office 365 | Benifits of Office 365 | Learn Office 365
What is Office 365 | Benifits of Office 365 | Learn Office 365
 
Bp101-Can Domino Be Hacked
Bp101-Can Domino Be HackedBp101-Can Domino Be Hacked
Bp101-Can Domino Be Hacked
 
Java On CRaC
Java On CRaCJava On CRaC
Java On CRaC
 
Oracle Data Integrator 12c - Getting Started
Oracle Data Integrator 12c - Getting StartedOracle Data Integrator 12c - Getting Started
Oracle Data Integrator 12c - Getting Started
 
Oracle Cloud
Oracle CloudOracle Cloud
Oracle Cloud
 
Introduction to Azure AD and Azure AD B2C
Introduction to Azure AD and Azure AD B2CIntroduction to Azure AD and Azure AD B2C
Introduction to Azure AD and Azure AD B2C
 
Exchange server.pptx
Exchange server.pptxExchange server.pptx
Exchange server.pptx
 
Overview of Microsoft Exchange Server
Overview of Microsoft Exchange ServerOverview of Microsoft Exchange Server
Overview of Microsoft Exchange Server
 
Atomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas HunterAtomicity In Redis: Thomas Hunter
Atomicity In Redis: Thomas Hunter
 
HCL Domino V12 - TOTP
HCL Domino V12 - TOTPHCL Domino V12 - TOTP
HCL Domino V12 - TOTP
 
Azure B2C
Azure B2CAzure B2C
Azure B2C
 

Destacado

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
 
Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQ
elliando dias
 

Destacado (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
 
Advanced messaging with Apache ActiveMQ
Advanced messaging with Apache ActiveMQAdvanced messaging with Apache ActiveMQ
Advanced messaging 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
 
Enterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQEnterprise Messaging with Apache ActiveMQ
Enterprise Messaging with Apache ActiveMQ
 
Mcollective orchestration tool 소개
Mcollective orchestration tool 소개Mcollective orchestration tool 소개
Mcollective orchestration tool 소개
 

Similar a 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
 

Similar a 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
 

Más de Bruce Snyder

Más 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
 

Último

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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (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
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

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