activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james.strac...@gmail.com>
Subject Re: QueueBrowser
Date Fri, 12 Jan 2007 12:56:54 GMT
This one has got me so many times with JMS.

http://incubator.apache.org/activemq/i-am-not-receiving-any-messages-what-is-wrong.html

On 1/12/07, petera <peter.anderson@egsgroup.com> wrote:
>
> Hi,
>
> I am using activemq ver 4.0.1 on a mac running OS x 10.4.8
>
> I am trying to use the queue browser to view messages on a queue but it does
> not seem to work. No messages
> are being returned when i issue the command:
>               Enumeration msgs = browser.getEnumeration();
>
> There are definitely messages on the queue and i can see them in the
> persistent activemq_msgs table.
>
> Is this a bug ? Or am i doing something wrong ?
>
> CODE:
>
>
>         try
>         {
> /*
>  * Create a JNDI API Initial Context object.
>  */
>               InitialContext init = new InitialContext() ;
>               Context envContext = (Context) init.lookup("java:comp/env") ;
> /*
>  * Look up Connection Factory and destination.
>  */
>               ConnectionFactory connectionFactory = (ConnectionFactory)
> envContext.lookup("jms/ConnectionFactory") ;
>
>               Queue queue = (Queue) envContext.lookup("jms/InvoiceQueue") ;
>
>               connection = connectionFactory.createConnection();
>
>               session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
>
>               QueueBrowser browser = session.createBrowser(queue);
>               Enumeration msgs = browser.getEnumeration();
>
>               if (!msgs.hasMoreElements()) {
>                   out.println("No messages in queue");
>               } else {
>                   while (msgs.hasMoreElements()) {
>                       Message tempMsg = (Message) msgs.nextElement();
>                       out.println("Message: " + tempMsg);
>                   }
>               }
>           } catch (JMSException e) {
>               out.println("Exception occurred: " + e.toString());
>           }
>         catch (NamingException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } finally {
>               if (connection != null) {
>                   try {
>                       connection.close();
>                   } catch (JMSException e) {
>                   }
>               }
>           }
>
>
>
>
> --
> View this message in context: http://www.nabble.com/QueueBrowser-tf2965665.html#a8297397
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 

James
-------
http://radio.weblogs.com/0112098/

Mime
View raw message