public class JmsContainer extends DefaultMessageListenerContainer { private static final Logger logger = Logger.getLogger(JmsContainer.class); public void start(){ startAdvisoryListener(); super.start(); } private void startAdvisoryListener(){ javax.jms.Connection connection; try { connection = getConnectionFactory().createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); connection.start(); Destination topic = session.createTopic("ActiveMQ.Advisory..>"); MessageConsumer consumerAdvisory = session.createConsumer(topic); consumerAdvisory.setMessageListener(new MessageListener() { public void onMessage(Message message) { if (message instanceof ActiveMQMessage) { ActiveMQMessage activeMessage = (ActiveMQMessage) message; Object command = activeMessage.getDataStructure(); if (command instanceof ConsumerInfo) { logger.info("A consumer subscribed to a topic or queue: " + command); } else if (command instanceof RemoveInfo) { RemoveInfo removeInfo = (RemoveInfo) command; if (removeInfo.isConsumerRemove()) { logger.info("A consumer unsubscribed from a topic or queue"); } else { logger.info("RemoveInfo, a connection was closed: " + command); } } else if (command instanceof ConnectionInfo) { logger.info("ConnectionInfo, a new connection was made: " + command); } else { logger.info("Unknown command: " + command); } } } }); } catch (JMSException e) { e.printStackTrace(); } } }
Friday, March 25, 2011
How to listen JMS disconnection?
I refere this.
Labels:
JMS
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment