5 Replies Latest reply: Sep 11, 2011 3:04 AM by Kshitiz Garg RSS

Deleting a destination with consumers attached via MBean?

Tom Jenkinson Master

Hi,

 

I am trying to delete a queue but there are consumers attached to it and as such I appear to be unable to do so, instead I get the errror message:

 

javax.management.MBeanException: HornetQException[errorCode=104 message=Cannot delete queue jms.queue.BTR_BAR on binding jms.queue.BTR_BAR - it has consumers = org.hornetq.core.postoffice.impl.LocalQueueBinding]
    at com.sun.jmx.mbeanserver.MBeanIntrospector.unwrapInvocationTargetException(MBeanIntrospector.java:283)

 

Is there any way I can delete this queue?

 

Thanks in advance,

Tom

 

PS This is using 2.1.2.Final

  • 1. Re: Deleting a destination with consumers attached via MBean?
    Clebert Suconic Master

    The error is what it is.. you can't delete a queue with consumers.

     

    You can remove consumers with closeConnectionsForAddress for instance on management operations.

  • 2. Re: Deleting a destination with consumers attached via MBean?
    Tom Jenkinson Master

    Thanks for the clarification Clebert, much appreciated.

  • 3. Re: Deleting a destination with consumers attached via MBean?
    Tom Jenkinson Master

    Hi Clebert,

     

    The problem with what you suggested is that it is possible for a client to join between issuing the closeConnectionsForAddress call and then a destroyDestination call.

     

    I was wondering if you would object to me raising a feature request for this? The reason being that our application was built using JBM1.4 and we are kind of expecting to be able to do this as we cannot guarantee to synchronize all instances of our application to tear them down consumer first and we are expecting to be able to destroy the destination with the exception being raised to notify the consumer.

     

    If this is not possible we can rewrite our application so each instance of the application listens to a topic which sends an alert to all connections to tear down their consumer and report to the caller that they know the destination is ready for deletion, thereby guaranteeing it safe to destroy but it would require quite a sophisticated group protocol to take care of instances joining during deletion.

     

    Perhaps the capability to force consumers to disconnect during delete could be added as a flag to destroyDestination?

     

    Tom

  • 4. Re: Deleting a destination with consumers attached via MBean?
    Clebert Suconic Master

    I consider the behaviour from JBM 1.4 broken. You would have disrupted Consumers when the queue was already deleted.

     

    You could however add a feature request to "force" consumers out when deleting a queue and doing it atomically. You could probably suggest a patch if you like.

     

    However this will probably force the entire connection to be out, not just the consumer. A client could be connected to several other queues at the same time the queue is being removed.

  • 5. Re: Deleting a destination with consumers attached via MBean?
    Kshitiz Garg Newbie

    I did this in the following manner:

     

    Stored all the consumers in a Map<String queueName, List<ClientConsumer>> queuesWithTheirConsumers. Now when I want to delete queueName, first I will do a 'close' on all its consumers:

     

    List<ClientConsumer> consumers = queuesWithTheirConsumers.get(queueName);

    for(ClientConsumer c : consumers){

         c.close();

    }

     

    and then call deleteQueue (queueName). It works

     

     

     

     

     

    removeQueueConsumers();

     

    stored