List of usage examples for javax.jms Session createBrowser
QueueBrowser createBrowser(Queue queue) throws JMSException;
From source file:org.apache.activemq.network.BrokerNetworkWithStuckMessagesTest.java
@SuppressWarnings({ "unchecked", "unused" }) private Object[] browseQueueWithJms(BrokerService broker) throws Exception { Object[] messages = null;/*from w ww. j a va2 s. c o m*/ Connection connection = null; Session session = null; try { URI brokerUri = connector.getUri(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUri.toString()); connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(queueName); QueueBrowser browser = session.createBrowser(destination); List<Message> list = new ArrayList<Message>(); for (Enumeration<Message> enumn = browser.getEnumeration(); enumn.hasMoreElements();) { list.add(enumn.nextElement()); } messages = list.toArray(); } finally { if (session != null) { session.close(); } if (connection != null) { connection.close(); } } LOG.info("+Browsed with JMS: " + messages.length); return messages; }