Nag, Thanks for the reply. I missed the link to the forum on the ActiveMQ site. I'll go back and find it. Thanks for the heads up.
I'm just writing a client that reads a queue. The code for posting to the queue works just fine, and I can pull messages of synchronously and with the stomp client. I'm just missing something in my understanding and code that is preventing my asynchronous consumer from looping through a queue until it is empty. Mike On Thu, Feb 17, 2011 at 11:25 AM, Nakarikanti, Nageswara < nnakarika...@dwd.in.gov> wrote: > For fast replys post it to Forum > > I did not see any code in your program that is responsible for producing > the messages into Queue you created? > > > Nag. > > -----Original Message----- > From: McDermott, Michael [mailto:michael_mcderm...@brown.edu] > Sent: Monday, February 14, 2011 7:44 AM > To: users@activemq.apache.org > Subject: Asynchronously emptying a queue > > Hello folks, > I'm an ActiveMQ noob and I'm trying to figure out how to write a program to > loop through the contents of the queue and having a devil of a time. I've > bought the Manning book and tried my best on google but have been unable to > find out how. > > From what I'm reading, it seems like I should set up an asynchronous > connection and implement the MessageListener interface. But when I do, I > don't usually seem to get back anything, let alone loop through the entire > queue. I was able to achieve the results in a pretty straight forward > manner using the Stomp client, so I think it is my Java. Any suggestions > on > where I've went awry: > > import javax.jms.*; > import javax.naming.* > import org.apache.activemq.*; > import java.util.Date; > > public class Consumera implements MessageListener { > > ActiveMQConnectionFactory connectionFactory; > Context ctx; > Connection connection; > Session session; > MessageConsumer consumer; > boolean useTransaction = false; > Queue queue; > Message message; > public void createConsumer() throws JMSException, NamingException { > try { > > ctx = new InitialContext(); > //this section is for local create > // Create a ConnectionFactory > > // ditrect connection factory > //connectionFactory = new ActiveMQConnectionFactory(username, password, > brokerURL); > //jndi connection factory > connectionFactory = > (ActiveMQConnectionFactory) ctx.lookup("remoteConsumerConnectionFactory"); > > // Create a Connection > connection = connectionFactory.createConnection(); > > > // Create a Session > session = connection.createSession(useTransaction, > Session.AUTO_ACKNOWLEDGE); > // Create the destination (Topic or Queue) > queue= (Queue) ctx.lookup("GoogleGroupQueue"); > > > consumer = session.createConsumer(queue); > consumer.setMessageListener(this); > connection.start(); > > // Create a MessageProducer from the Session to the Topic or Queue > } > > catch (Exception e) { > System.out.println("Caught: " + e); > e.printStackTrace(); > } > } > > public void onMessage(Message message) { > System.out.println("Received message: " ); > //if (message instanceof TextMessage) { > // System.out.println("Received message: " + message); > //} > } > public void closePublisher() throws JMSException { > try { > // Clean up > consumer.close(); > session.close(); > connection.close(); > System.out.println("Closed connection"); > } > catch (Exception e) { > System.out.println("Caught: " + e); > e.printStackTrace(); > } > } > > public static void main(String[] args) throws JMSException { > > Consumera consumer = new Consumera(); > try{ > consumer.createConsumer(); > } catch (NamingException e) { > e.printStackTrace(); > } finally { > consumer.closePublisher(); > } > } > } > > > > > Mike > -- Michael J. McDermott Lead Developer, Identity and Access Management Brown University Sent from someone else's iphone.