unable to browse queues using jms QueueBrowser

前提是你 提交于 2020-02-05 06:51:31

问题


In the jboss admin-console page I can view the current number of items in my queue.

However I'm getting empty enumeration from queueBrowser.getEnumeration().

Below is my code to browse the queue:

public class JMSQueueBrowser {
private final Log log = LogFactory.getLog(getClass());

private QueueConnectionFactory connectionFactory;
private Queue   queue;
private QueueBrowser qBrowser;
private QueueSession qSession;
private QueueConnection qConn;

public JMSQueueBrowser() {
    initialize();
}

private  void initialize()  {
    try {
        InitialContext initialContext = new InitialContext();
        connectionFactory = (QueueConnectionFactory)initialContext.lookup("java:comp/env/jms/MyQCF");
        queue             = (Queue)initialContext.lookup("queue/sampleQueue");
        qConn             = (QueueConnection) connectionFactory.createConnection();
        qConn.start();
        qSession = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        qBrowser = qSession.createBrowser(queue);
        initialContext.close();
    } catch (NamingException e) {
        log.error(e.getMessage());
    } catch (JMSException e) {
        log.error(e.getMessage());
    }
}

public void browseQueue() {
    try {
        log.info("---------Queue Name: "+queue.getQueueName()+"-----------");
        log.info("---------Queue Has Elements: "+qBrowser.getEnumeration().hasMoreElements()+"-----------");
    } catch (JMSException e) {
        log.error(e.getMessage());
    }
}}

The log is always being the same as following:

INFO  JMSQueueBrowser - ---------Queue Name: sampleQueue-----------
INFO  JMSQueueBrowser - ---------Queue Has Elements: false----------

The library used for JMS Queue is jbossall-client.jar.

Any answer will be appreciated. Thanks in advance.

来源:https://stackoverflow.com/questions/28408438/unable-to-browse-queues-using-jms-queuebrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!