martedì 3 aprile 2012

Integration with AMQ and application blocks

AMQ is a messaging middleware commonly used in enterprise applications.
Often,  incorrect use of the AMQ broker because of complete blocks of the system that often lead to failure starting the application server (application server hangs without completing start procedure).
In this section some common problems and possible solutions emerged for persistent topic:1 - Clients subscribe to persistent topic and don't consume messages
If a client subscribes to a queue/topic  and never consumes meggases the broker will retain the messages on file. With defauklt AMQ settings when persistence storage exeeds 1 GB  AMQ stops to store messages and sends to client  flooding messages.
To find if this is your problem check data directory size under $ AMQ_HOME/brokers/data.
es. du -ksh $ AMQ_HOME/brokers/data

 
Then you may proceed as follows:a) Set client connection mode with failover option enabled (prevents system block).connectionFactory.createConnection connection = ();connection.setClientID ("mclientid");connection.createSession session = (false, Session.AUTO_ACKNOWLEDGE);where  

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_BROKER_URL);

 public static final java.lang.String DEFAULT_BROKER_URL = 'failover :/ / tcp :/ / localhost: 61616

b) Clear the persistence of the queue.After turning off AMQ type this command to clear the datafind $ AMQ_HOME / brokers/data   -name "*"-type f-print-exec rm-f {} \;2 - Block AMQ broker because of persistence of corrupt fsLook at the log file when it appears AMQ error message like below demonstrates the problem is related to corruption of data on AMQ file suystem, this is a problem that sometimes happens in virtual machines.The solution is always to empty the AMQ persistence before rebooting:[Main] ERROR BrokerService - Failed to start ActiveMQ JMS Message Broker. Reason: org.apache.activemq.kaha.impl.index.BadMagicExceptionorg.apache.activemq.kaha.impl.index.BadMagicException
        
at org.apache.activemq.kaha.impl.index.IndexItem.read (IndexItem.java: 141)
        
at org.apache.activemq.kaha.impl.index.StoreIndexReader.readItem (StoreIndexReader.java: 50)
        
at org.apache.activemq.kaha.impl.index.IndexManager.initialize (IndexManager.java: 207)
        
at org.apache.activemq.kaha.impl.index.IndexManager. <init> (IndexManager.java: 60)
        
at org.apache.activemq.kaha.impl.KahaStore.getIndexManager (KahaStore.java: 366)
        
at org.apache.activemq.kaha.impl.KahaStore.getMapContainer (KahaStore.java: 219)
   
        at org.apache.activemq.broker.region.AbstractRegion.createDestination (AbstractRegion.java: 464)
        
at org.apache.activemq.broker.jmx.ManagedQueueRegion.createDestination (ManagedQueueRegion.java: 56)
        
at org.apache.activemq.broker.region.AbstractRegion.addDestination (AbstractRegion.java: 120)
        
at org.apache.activemq.broker.region.RegionBroker.addDestination (RegionBroker.java: 268)
        
at org.apache.activemq.broker.BrokerFilter.addDestination (BrokerFilter.java: 142)
        
at org.apache.activemq.broker.BrokerFilter.addDestination (BrokerFilter.java: 142)
        
at org.apache.activemq.advisory.AdvisoryBroker.addDestination (AdvisoryBroker.java: 153)
        
at org.apache.activemq.broker.BrokerFilter.addDestination (BrokerFilter.java: 142)
        
at org.apache.activemq.broker.MutableBrokerFilter.addDestination (MutableBrokerFilter.java: 149)
        
at org.apache.activemq.broker.region.AbstractRegion.start (AbstractRegion.java: 94)
        
at org.apache.activemq.broker.region.RegionBroker.start (RegionBroker.java: 180)
        
at org.apache.activemq.broker.jmx.ManagedRegionBroker.start (ManagedRegionBroker.java: 100)
        
at org.apache.activemq.broker.TransactionBroker.start (TransactionBroker.java: 112)



C) other best praticse tips:
- use explicit message acknowledge because otherwise ( code example:session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);)  message acknowledge occurs only at the end of onMessage() method ( could affect performance). 
- set message expiration time .
-  use PERSISTENT delivery mode only if you really need it !! ( producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- do not create  ActiveMQConnectionFactory for each new message sent (reuse it).
- use message selector on client side to avoid unwanted messages.


D) others usefull commands to amq status inspection
Topic/Queue information;
activemq-admin query --jmxurl service:jmx:rmi:///jndi/rmi://localhost:3099/jmxrmi -QTopic=*
activemq-admin query --jmxurl service:jmx:rmi:///jndi/rmi://localhost:3099/jmxrmi  -QQueue=*
( QueueSize >> 0  Wrong)(DequeueCount, EnqueueCount, QueueSize, DispatchCount are usefull kpi)


EnqueueCount: The number of messages that have been written to the queue
over the lifetime of the queue.

DequeueCount: The number of messages that have been successfully (i.e.,
they’ve been acknowledged from the consumer) read off the queue over the
lifetime of the queue.

DispatchCount: The number of messages that have been dispatched (sent) to
the consumer over the lifetime of the queue. Note that dispatched messages
may not have all been acknowledged.

InFlightCount: The number of messages that have been dispatched and are
currently awaiting acknowledgment from the consumer. So as this number
decreases, the DequeueCount increases.

QueueSize: The number of messages that currently reside in the queue.

AverageEnqueueTime: On average, the amount of time (ms) that messages
remained enqueued. Or average time it is taking the consumers to
successfully process messages.

MaxEnqueueTime: The maximum amount of time that messages remained enqueued.

MinEnqueueTime: The minimum amount of time that messages remained enqueued.


 activemq-admin browse --amqurl tcp://localhost:61616 SYSTEM.TRAP.NOTIFICATION.JMSTOPIC


Open Connections from/to AMQ (suppose 61616 amq listening port) netstat -tuplan | grep 61616 | wc -l  lsof -i:61616|wc -l

Nessun commento:

Posta un commento