activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From czy11421 <czy11...@gmail.com>
Subject Re: error in subscribing topic
Date Sun, 13 Sep 2009 16:55:31 GMT
Rob,
Thanks for your reply.

Here is another question. If I use MessageListener, how could I start to 
receive message ? Coding as below, the Listener will NOT output message. 
Did I miss something ?

Thanks.
Edward

//---------------------------------
session = conn.createTopicSession(false, 
TopicSession.AUTO_ACKNOWLEDGE);       

            javax.jms.Topic mytopic = session.createTopic("STOCKS.SUNW");

            Test2.MyListener listener = new Test2.MyListener();

            javax.jms.TopicSubscriber subscriber = 
session.createSubscriber(mytopic);
           
            /**  == works
            while(true){
                Message message = subscriber.receive();
                TextMessage text = (TextMessage) message;
                System.out.println(text.getText());
                Thread.sleep(1000);
            }
            **/

            subscriber.setMessageListener(listener);
//-------------------------------------------

//-----------------------------------
static class MyListener implements MessageListener {
        public void onMessage(Message message) {
            System.out.println("Message: ");
            TextMessage text = (TextMessage) message;
            try {
                System.out.println("Message: " + text.getText());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
//-----------------------------------

Mime
View raw message