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(

 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 ( 141)
at org.apache.activemq.kaha.impl.index.StoreIndexReader.readItem ( 50)
at org.apache.activemq.kaha.impl.index.IndexManager.initialize ( 207)
at org.apache.activemq.kaha.impl.index.IndexManager. <init> ( 60)
at org.apache.activemq.kaha.impl.KahaStore.getIndexManager ( 366)
at org.apache.activemq.kaha.impl.KahaStore.getMapContainer ( 219)
        at ( 464)
at ( 56)
at ( 120)
at ( 268)
at ( 142)
at ( 142)
at org.apache.activemq.advisory.AdvisoryBroker.addDestination ( 153)
at ( 142)
at ( 149)
at ( 94)
at ( 180)
at ( 100)
at ( 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