aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes how do i remove consumers on a queue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how do i remove consumers on a queue" Watch "how do i remove consumers on a queue" New topic
Author

how do i remove consumers on a queue

robert stevens
Greenhorn

Joined: Jul 05, 2007
Posts: 7
i am dynamically setting up a jms queue which i use to talk across 2 different jvms. Now when i try to delete that queue i get a big fat exception ... the essence of which is as below

ERROR [ORB-Worker-7] - Failed to remove destination=aqueue
javax.jms.JMSException: Cannot delete destination aqueue-true since there are active consumers.
aqueue is the name of the queue that i create.

Now i before i remove the queue i do probe the jms to find if it exists as below

JMSAdministrator jmsAdministratorInstance = JMSAdministrator.getInstance();
if(jmsAdministratorInstance.queueExists(queueName)

on finding that the queue i remove the active consumers by the following

Vector<String> consumerVector = new Vector();
try {
consumerVector= this.handleToAdminServer.getDurableConsumers(queueName);
//assumes no more than 100 consumers....
String[] consumerArray = new String[100];
consumerVector.copyInto(consumerArray);
int i=0;
while (i< consumerArray.length)
{
System.out.println("Consumer name :- " + consumerArray[i]);
if(this.handleToAdminServer.removeDurableConsumer(consumerArray[i]))
{
System.out.println("Successfully removed consumer " + consumerArray[i]);
}
if(this.handleToAdminServer.unregisterConsumer(consumerArray[i]))
{
System.out.println("Successfully deactivated " + consumerArray[i]);
}
i++;
}
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}


after having removed the consumers i go ahead to remove the queue by the following
try {
this.handleToAdminServer.removeDestination(queueName);
this.listOfAactiveQueues.remove(queueName);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


now my program runs properly but the openjms (which i have opened in a linux terminal) throws the excetption which i have mentioned on top. Now i am a totally novice in the area. Can anyone please help me out.
robert stevens
Greenhorn

Joined: Jul 05, 2007
Posts: 7
problem solved \m/
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

Why not share your solution so others with a similar problem might benefit?


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do i remove consumers on a queue