2 Replies Latest reply on Dec 28, 2007 7:23 AM by Tim Fox

    Destruction/cleanup of temporary queues

    P Duffy Newbie

      I seem to have a few temporary queues hanging around within my broker after the client app exits.

      - what sequence of JMS calls will cause the temp Q to be destroyed?

      - In the event of abnormal client exit, is there some way in which the temp Qs can be auto cleaned up by the broker?

      Thanks

        • 1. Re: Destruction/cleanup of temporary queues
          P Duffy Newbie

          The following test client confirms that simply closing a Connection will not delete any created temporary queues. Performed w/ JBM 1.3 and EAP 4.2. This example requires the consumer be closed and the temp Q explicitly deleted to cause removal of the temp Q. This conflicts with JEE JavaDoc, which states that closing the connection will remove temporary queues.

          Further, if the connection is simply closed, the temp Q appears to be a permanent resource leak within the broker (confirmed w/ JNDIView).

          Please advise. If the answer is "move to 1.4", please confirm that this issue is resolved in 1.4...I am unable to find any info in the JIRA.

          package com.cisco.nm.comet.api.test;
          
          import javax.jms.Connection;
          import javax.jms.ConnectionFactory;
          import javax.jms.JMSException;
          import javax.jms.MessageConsumer;
          import javax.jms.MessageProducer;
          import javax.jms.Queue;
          import javax.jms.Session;
          import javax.jms.TemporaryQueue;
          import javax.naming.InitialContext;
          import javax.naming.NamingException;
          
          public class JMSTempQDelete
          {
           private static final String requestQueueName = "queue/cduRequestRouterQueue";
          
           public static void main(String args[])
           {
           try
           {
           // Get the JNDI context.
           //
           InitialContext ctx = new InitialContext();
          
           // Lookup the connection factory and create connection.
           //
           ConnectionFactory factory = (ConnectionFactory)ctx.lookup("ConnectionFactory");
           Connection connection = factory.createConnection();
          
           // Create the response session, temp reply Q, and response consumer.
           //
           Session responseSession = connection.createSession(false,
           Session.AUTO_ACKNOWLEDGE);
           TemporaryQueue responseQueue = responseSession.createTemporaryQueue();
           MessageConsumer consumer = responseSession.createConsumer(responseQueue);
          
           // JBM 1.3. It is neccessary to close consumer and explicitly
           // delete temp Q to remove the temp Q from the broker.
           //
           // This conflicts with info at http://java.sun.com/javaee/5/docs/api/ ...
           // "Closing a connection causes all temporary destinations to be deleted"
           //
           consumer.close();
           responseQueue.delete();
          
           connection.stop();
           connection.close();
           }
           catch (NamingException e)
           {
           // TODO Auto-generated catch block
           e.printStackTrace();
           }
           catch (JMSException e)
           {
           // TODO Auto-generated catch block
           e.printStackTrace();
           }
           }
          }
          


          • 2. Re: Destruction/cleanup of temporary queues
            Tim Fox Master

            The actual temporary queue _does_ get deleted on connection close, or explicit delete.

            However it seems the destination object remains in JNDI if you close the connection without explicitly deleting the temp destination. This will give a small resource leak (the actual destination object is very small).

            Since the leak is small, hopefully won't cause problems, but if so, workaround for now would be to make sure you explicitly delete the temp destination before closing the connection.