activemq-artemis

How to destroy a queue on ActiveMQ Artemis using management message


I am successfully using the ActiveMQ Artemis Management API to run admin commands on the broker. Creating messages, deleting them, moving them, restoring DLQ messages, pruning a queue, etc. all works fine. Except destroying a queue.

I use the following code:

Message request = queueSession.createMessage();
JMSManagementHelper.putOperationInvocation(request, ResourceNames.BROKER, "destroyQueue​", queueName);
Message reply = managementRequestor.request(request);
        
if (JMSManagementHelper.hasOperationSucceeded(reply)) {
    System.out.println("Invoked management operation destroyQueue on server.");
} else {
    throw new JMSException("The management operation destroyQueue did not succeed.");
}

This results in the exception being thrown no matter which queue I try to destroy. Using the admin console I have no problem destroying the same queue so the broker has no real problem with destroying the queues I try to destroy.

The structure of my code is correct because I use it with many other management commands. There's something going on with the destroyQueue command.

I get no real error feedback either on the return message or in the log of the broker, so I have no idea what is going wrong.

What am I doing wrong here?


Solution

  • There may a timing issue where consumers are present on the queue when you attempt to destroy it.

    In any case, if you want to get a better understanding about the nature of the failure you should use JMSManagementHelper#getResult(javax.jms.Message). The JavaDoc states:

    Returns the result of an operation invocation or an attribute value. If an error occurred on the server, hasOperationSucceeded(Message) will return false. and the result will be a String corresponding to the server exception.

    For example:

    Message request = queueSession.createMessage();
    JMSManagementHelper.putOperationInvocation(request, ResourceNames.BROKER, "destroyQueue​", queueName);
    Message reply = managementRequestor.request(request);
            
    if (JMSManagementHelper.hasOperationSucceeded(reply)) {
        System.out.println("Invoked management operation destroyQueue on server.");
    } else {
        throw new JMSException("The management operation destroyQueue did not succeed. Result: " + JMSManagementHelper.getResult(reply));
    }