Queue Browser In ActiveMQ-5.10

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Queue Browser In ActiveMQ-5.10


I am browsing queue messages periodically using below method:

I have list of Queues and I am creating single session for all the browsers. Is this the correct way of browsing or I should use create separate connections/sessions  ?

public Map<String, List<GearMessage>> getQueueMessages()
            Map<String, List<GearMessage>> queueMessageMap = new HashMap<String, List<GearMessage>>();
            try {
                 Connection conn = connectionFactory.createConnection();
                 Session session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
                 for (Entry<String, Queue> entry : queueMap.entrySet()) {
                     List<GearMessage> messageList = new ArrayList<GearMessage>();
                     String key = entry.getKey();
                     Queue queue = entry.getValue();
                     QueueBrowser browser = session.createBrowser(queue);
                     Enumeration e = browser.getEnumeration();
                     while (e.hasMoreElements()) {
                         Message msg = (Message) e.nextElement();
                         GearMessage gearMessage = messageParser.parse(msg);
                     queueMessageMap.put(key, messageList);