0 Replies Latest reply on Jun 29, 2011 1:55 AM by navnath

    Want to add MessageListener to Programmatically created Queue forever

    navnath

        

       

      I am creating JMS Queue at run time and trying to add Listener after creation of queue. Now I am able to bind Listener with newly create queue. Here is my sample code to bind Listener

              Context ctx = new InitContex();

              QueueConnectionFactory queueConnectionFactory =
                  (QueueConnectionFactory) ctx.lookup("java:/JmsXA");

              Queue myQueue = (Queue)ctx.lookup("queue/myQueue");
              QueueConnection queueConnection =
                    queueConnectionFactory.createQueueConnection();

            QueueSessionqueueSession=queueConnection.createQueueSession(true,Session.AUTO_ACKNOWLEDGE);

              javax.jms.QueueReceiver queueReceiver = queueSession.createReceiver(myQueue);
              MessageListener myListener = new MyListenerBean();
              queueReceiver.setMessageListener(myListener);

      But using above code I need to bind Listener every time whenever I add new message in Queue. Is there any way to bind Listener at once and use it till server didn't get down.(This can be done with configure Queue in JBoss, But I want to bind Queue which I have created at run time.)

      Thanks in advance.