Try enabling JMX in your embedded broker and check if there are really messages being enqueued in the queue specified.

Does using an actual consumer instead of a queue browser works?

Priya Parvatikar wrote:
Hi,

I am trying to use a QueueBrowser to browse messages sent using an embedded
broker. I am using ActiveMQ version 4.0.2. The broker is set up using
new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");

However the QueueBrowser doesn't appear to get any messages i.e.
browser.getEnumeration().hasMoreElements() returns false.  Here's the code I
am using -
public void initialise(){
    try {
        ConnectionFactory connFactory = new
ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");          
        Connection connection = connFactory.createConnection();
        Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
        javax.jms.Queue queue =
(javax.jms.Queue)jndiUtil.getJndiEntry(queueName);
        browser = session.createBrowser(queue);
        connection.start();
    } catch (NamingException e) {
        System.err.println("Got NamingException : " + e.getMessage());
    } catch (JMSException e) {
        System.err.println("Got JMSException : " + e.getMessage());
    }

}

public void browseMessages {
    try {
        Enumeration msgEnum = browser.getEnumeration();
        System.out.println("has more elements is " +
msgEnum.hasMoreElements());
    }catch (JMSException e) {
        System.err.println("Got JMSException : " + e.getMessage());
    }
}

The initialise() method is called before the sender sends messages to the
queue and the browseMessages() method is called after the sender has sent a
message.  Could you please advise me about this?  Apologies if I am missing
something obvious.

Thanks,
Priya




Reply via email to