views:

321

answers:

1

I tried to implement MessageListener, but it dosen't work, but when I use MessageListner, it doesn't work. So what should I do that MessageListener starts working, I'm using jboss 4.02.

recv.receive(); // This works

recv.setMessageListener(new ExListener()); // This doesn't work

    public static class ExListener 
    implements MessageListener
    {
        public void onMessage(Message msg)
        {
            TextMessage tm = (TextMessage) msg;
            try {
                System.out.println("onMessage, recv text="+tm.getText());
            } catch(Throwable t) {
                t.printStackTrace();
            }
        }
    }
A: 

The problem could be that the class that registers the listener has ended and the listener object goes out of existence. You should keep the object live and running to receive the message.

Ram